From: Oti <oh...@ya...> - 2002-09-19 21:48:51
|
[ Ype Kingma, answering Peter Rupp] > > 4) When I create an instance of a Java type, running Jython's > > "type(<variable>) against the instance variable shows me > > <jclass.org.python.core.PyJavaInstance at <hex #>> > > > > Is there a way to determine the real Java class type? > > There is, but I'm not sure. In jython you might try: > yourObject.__tojava__().__class__ You might just use yourObject.__class__, as here: Jython 2.1 on java1.4.1-rc (JIT: null) >>> from java.util import HashMap >>> map = HashMap() >>> type( map ) <jclass org.python.core.PyJavaInstance at 11665455> >>> map.__class__ <jclass java.util.HashMap at 13086732> >>> map.__class__ == HashMap 1 >>> keySet = map.keySet() >>> keySet.__class__ <jclass java.util.HashMap.KeySet at 5525185> >>> keySet.__class__ == HashMap.KeySet 1 >>> As you see, it works for directly instantiated objects and for results of method calls, while: >>> map.__tojava__().__class__ Traceback (innermost last): File "<console>", line 1, in ? AttributeError: __tojava__ >>> AFAIK __tojava__() is used in embedding, e.g. if you want to convert a PyObject into its java counterpart. Best wishes, Oti. __________________________________________________ Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! http://sbc.yahoo.com |