JClassType source and isGenericType()

59 views
Skip to first unread message

pansen

unread,
Jun 14, 2011, 4:27:52 PM6/14/11
to Google Web Toolkit
hi,

assuming i'm in a generator and receive a ``JClassType source`` which
is in that case a ``org.test.Foo<Bar>``.

then ``souce.isGenericType()`` returns ``null``
but ``source.getParameterizedQualifiedSourceName()`` returns
"org.test.Foo<Bar>".
whereas ``source.getSimpleSourceName()`` only returns "Foo"

...which is a problem for me.

what can i call to see this is a specialization of a generic? e.g.
something like ``source.base().isGenericType()``.

what can i call to see the specialization of this class - in this case
i want the result of "Bar".

thx a lot, andi

Adolfo Panizo Touzon

unread,
Jun 15, 2011, 4:17:44 AM6/15/11
to google-we...@googlegroups.com
JClassType[] typeArgs = 
     type.getImplementedInterfaces()[0].isParameterized().getTypeArgs();
                      
JClassType elementType = typeArgs[0];

Did you try with getTypeArgs(); ????


2011/6/14 pansen <andi....@googlemail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.




--
El precio es lo que pagas. El valor es lo que recibes.
Warren Buffet

lemaiol

unread,
Jun 15, 2011, 7:26:26 AM6/15/11
to Google Web Toolkit
How is it defined?

is it something like:

private Foo<Bar> value;

or like:

private FooBar value;

where FooBar is "public class FooBar extends Foo<Bar> {..."

If it is the first, the problem is type erasure in Java generics. From
the "declaration" of the field, you cannot read the type. If you use
the second, it should work because the generic typeis "captured /
fixed" in the FooBar class definition.

If the second does not work, tell me and I will send you a working
example.

cheers,
Berto
Reply all
Reply to author
Forward
0 new messages