You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
fromorg.pkgimportMyClassasMyClass1
2nd approach:
MyClass2=JClass("org.pkg.MyClass")
How do we create an instance of such a class?
1st approach (per the quickguide):
myObject1=MyClass1()
2nd approach:
I tried this without success:
myObject2=MyClass2.getConstructor().newInstance()
This fails with an error like this:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [24], in <cell line: 1>()
----> 1 MyClass2.getConstructor()
AttributeError: type object 'org.pkg.MyClass' has no attribute 'getConstructor'
The text was updated successfully, but these errors were encountered:
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...
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:
The text was updated successfully, but these errors were encountered: