On Sat, 3 Apr 2010, Andi Vajda wrote:
On Apr 3, 2010, at 11:38, Bill Janssen <jans...@parc.com> wrote:
Does JCC support templated types yet?
Yes, Lucene Java moved to Java 5 and makes extensive use of generics in the
3.x release series.
I added support for that in JCC 2.5.
In particular, I'd like to be able to say,
--sequence List<com.parc.goodstuff.Stuff>
'size:()I'
'get:(I)Lcom/parc.goodstuff.Stuff;'
The first arg to --sequence is that of an existing class, and the following,
the actual signatures of existing methods on it.
If you define a class foo parameterized on type T and that type is the return
type of a method, that type is used, at runtime, as the wrapper for the
return value.
JCC does not generate code for all known expansions of a generic class - that
would lead to serious code explosion. Instead, the python instance of an
instatiated parameterized java class contains the type parameters used and
the wrapper methods use them to produce python return objects or accept
python parameters of the expected types.
The support for generics is good enough for Lucene's usage - not bad:-) - but
may have some holes and bugs still. I recently fixed a bug on trunk with
failing to inherit type parameters to inner classes, for example.
Also, there doesn't seem to be a way, from python, to directly instantiate a
class passing it type parameters. There is from C++, of course. Consider that
an oversight. I should add support for that.
I added support for a new method on classes that can be parameterized called
'of_'. It takes one or more wrapper class parameters, corresponding to the
parameters the java class was declared with.
For example:
>>> a=ArrayList().of_(String) # instantiate an ArrayList<String>
>>> a.add('foo')
True
>>> a.get(0)
<String: foo>
>>> a.of_(None) # reset its type parameter to nothing
<ArrayList: [foo]>
>>> a.get(0)
<Object: foo>
>>> a.of_(Double) # mess its type parameters up
<ArrayList: [foo]>
>>> a.add(1.5)
True
>>> a.get(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: <type 'Double'>
>>> a.get(1)
<Double: 1.5>
>>>
This is checked into jcc's trunk.
Andi..