eliminate gcjh?
Eric Blake
ebb9@byu.net
Thu Mar 11 14:28:00 GMT 2004
Tom Tromey wrote:
> Per> One important question: can we map Java generic classes into C++
> Per> generic classes in gcjh? How should we handle generic classes
> Per> in gcjh?
>> I suspect we should just ignore the genericity. Java generics don't
> really work like C++ templates. In C++ you instantiate the template
> for each set of parameters. In Java you emit a single implementation
> for a template by doing erasure on the parameterized types. So for
> instance in my earlier message, something like `class Base<T>' emerges
> from code generation as (basically) `class Base<Object>'.
I haven't thought about the C++ headers of generic types. Maybe it's time to
research what javah does for JNI in 1.5? But you are right that generics and
templates are not equivalent, which is why Sun is so adamant that their
feature not be called templates.
>> There's a lot here I don't know, however. For instance, I don't know
> what reflection returns when you ask about parameterized types.
> Perhaps it just returns the raw type.
Reflection has been upgraded to support generics; in particular,
java.lang.Class is genericized. The expression Foo.class now has the
compile-time type Class<Foo>, so that 'Foo f = Foo.class.newInstance()' works
as a synonym for (the faster) 'Foo f = new Foo()'. And new interfaces and
classes are added to java.lang.reflect to query generic signatures.
Reflection also handles enums and annotations, as well as a new class file
attribute EnclosingMethod for local and anonymous classes.
>> Other factors are our goals for CNI and what the g++ maintainers will
> let us put into g++.
>> Tom
>
--
Someday, I might put a cute statement here.
Eric Blake ebb9@byu.net
More information about the Java
mailing list