Hi Jonah,
There is no direct method to get the java.lang.Class from a
py4j.java_gateway.JavaClass. I used to just call Class.forName(fqn)
when I needed a java.lang.Class on the python side. I'm not opposed to
a feature request to support .class, but in the meantime, here are a
few workarounds that are more robust than Class.forName:
1. If you have an instance, you can always use .getClass()
ArrayList = gateway.jvm.java.util.ArrayList()
ArrayListClass = ArrayList.getClass()
This won't work for java.lang.String or primitives though.
2. You can use Py4J's ReflectionUtil, since the .class attribute would
likely end up using it:
ReflectionUtil = gateway.jvm.py4j.reflection.ReflectionUtil
JavaString = ReflectionUtil.classForName("java.lang.String")
If you have a py4j.java_gateway.JavaClass instance, you would do:
String = gateway.jvm.py4j.java.lang.String
ReflectionUtil = gateway.jvm.py4j.reflection.ReflectionUtil
JavaString = ReflectionUtil.classForName(String._fqn)
Since 0.9.2, the class loading strategy can be modified globally and
everything goes through ReflectionUtil.
Regarding the implementation of an hypothetical .class attribute: the
Java side of Py4j does not keep references to
py4j.java_gateway.JavaClass: it refetches the class through reflection
every time a static method, static field, or constructor is called.
That's why ultimately, a call to .class would end up calling
ReflectionUtil.
HTH,
Barthelemy
> --
> You received this message because you are subscribed to the Google Groups
> "Py4J Support and Comments" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
py4j+uns...@py4j.org.
> To post to this group, send email to
py...@py4j.org.
> To view this discussion on the web visit
>
https://groups.google.com/a/py4j.org/d/msgid/py4j/5aa621ea-242f-4fd7-9eee-97bcf82eb3da%40py4j.org.