Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access javas ".class" attribute in jython code?

Tags:

java

jython

In java, my code looks like:

new Injector(ClassToInjectOn.class, whatever)

so, the Injector class wants some Class<> argument. Works fine when doing things in Java.

But now I want to configure an injector object using jython.

I tried:

Injector(ClassToInjectOn.class, whatever) 

results in:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: instance attr: class

I tried auto-completion; and found that I could use ClassToInjectOn.__class__ ... but then the Class object that is passed into the injector will be java.lang.Class (but should be ClassToInjectOn.class).

Unfortunately searching for python and ".class" doesn't really provide useful answers.

like image 600
GhostCat Avatar asked Feb 18 '26 13:02

GhostCat


1 Answers

In python ClassToInjectOn is the class object. This is why ClassToInjectOn.__class__ gives you java.lang.Class, because that's what the class of a class object. So you need only write:

Injector(ClassToInjectOn, whatever) 
like image 124
Dunes Avatar answered Feb 21 '26 15:02

Dunes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!