A few things that expand upon your original question:

1. A generic (or parameterized) class like List<Class<?>> will see type erasure. As far as Jython, or any Java program is concerned, it's just a List of Object. However, Java does do dynamic type checking here by using a cast (implicitly added by the compiler if working with generics, you might have thought it was just statically type checking!) to maintain type safety.

We can further just take advantage of how Jython can coerce parameters to arrays; it's possible to pass a Python list to Java methods expecting arrays:


This is probably the way you want to use it, because it's simplest.

2. Java arrays do carry type information of what they contain - there is no type erasure. To construct Java arrays, you can use either the array or jarray module. I prefer to use the normal Python array module, but with the extended support in Jython extension that you can use some class (aClass here) instead of a typecode:

array.array(aClass [, iterable])

In either array or jarray, any such constructed arrays are just Java arrays of aClass, with potential gains in efficiency and reduced overhead in converting back & forth between Python and Java.

3. For the specific case of using a primitive for double you can either use:

a) array.array('d'[, iterable])
b) array.array(java.lang.Double.TYPE [, iterable])

with a) just translated to b) internally, so they are completely equivalent, except that a) is normal Python, b) is the extended Jython version.

- Jim

On Sun, Jul 28, 2013 at 6:43 AM, Eric Berryman <eric.berryman@gmail.com> wrote:

Is it possible to pass an object "List<Class<?>> types" from jython to java?  Maybe using jarray?

types.set(0, double.class);
(note I would like to pass the primitive) 

Thank you!

See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
Jython-users mailing list