user972946
user972946

Reputation:

How do I obtain the type of a Java instance in Jython?

from java.util import LinkedList
type(LinkedList())

The code above only gives "type 'javainstance" as output, however I wish to know the real Java instance type, which should be "LinkedList" in that case. Is this possible?

Thank you!

by the way, my version is jython 2.2.1

Upvotes: 3

Views: 3091

Answers (3)

smunk
smunk

Reputation: 324

I think you should be able to use

lst =LinkedList()
lst.class

Similar to the way that you would in java.

Upvotes: 0

Edmon
Edmon

Reputation: 4872

Howard, if you are on older Jython then try to call

LinkedList.getClass()

and

object.getClass().getName()

Upvotes: 2

Henk Langeveld
Henk Langeveld

Reputation: 8446

Just installed the latest jython last night. Let's take a look...

Jython 2.5.3rc1 (2.5:8fd14231e553, Aug 7 2012, 10:29:09)
[Java HotSpot(TM) 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_31
>>> type(LinkedList)
<type 'java.lang.Class'>
>>> l = LinkedList()
>>> type( l )
<type 'java.util.LinkedList'>

What version of Jython do you have? I know from experience that some levels of inspection only appeared in later versions.

Upvotes: -1

Related Questions