Closed NicolasRouquette closed 2 years ago
As you can see in the quickstart guide, call a class as a function to construct an object.
java::
public MyClass(int i) {...}
python::
MyClass = jpype.JClass("MyClass")
instance = MyClass(1)
Thanks for the quick reply!
Okay I see your confusion. It does not matter how a class is created, all methods allow constructors to be called as functions.
You can use an import.
from com.mypackage import MyClass
Or you may call JClass directly.
MyClass = JClass("com.mypackage.MyClass
Or use JPackage
MyClass = JPackage("com.mypackage").MyClass
It is possible to access reflection methods but those require the "class" rather than the class wrapper. I do not generally recommend it, but you should be able to do something like...
MyClass.class_.getConstructor()
Since there are two ways to import a Java class, the doc should describe how to create corresponding instances from them.
1st approach (requires Java9 module in the jar):
2nd approach:
How do we create an instance of such a class?
1st approach (per the quickguide):
2nd approach:
I tried this without success:
This fails with an error like this: