At runtime you can take class Foo<T> and determine that it requires
generic type parameters, but you can take an instance of Foo<T> and
find out what generic type parameter T is. For a decompiler (while I'm
just speculating) it shouldn't need to know what type an instance of
Foo<T> is as it's just trying to determine if Foo<T> requires a type
parameter.
thus, you can't do something like
if (String.class == foo.getClass().getGenericArguments().get(0)) {
//
}
or...
class Foo<T> {
void bar() {
if (T.class == String.class) {
//
}
}
}
In contrast, with C# you can do the former as
if (myList.GetType().GetGenericArguments()[0] == typeof(String)) {
//
}
and the latter as
class Foo<T> {
public void Bar() {
if (typeof(T) == typeof(String)) {
//
}
}
}
-Brett
On Nov 4, 11:16 pm, "Frederic Simon" <[EMAIL PROTECTED]> wrote:
> What's funny, is that Joe was saying: If it's in the class file it should be
> in the reflection API as an extension... Well that's exactly how it goes.
> All the "erased by erasure" information is in the class file. So, you can
> query generics and annotations on a class file.
> The problem if you get a List object as a parameter here you lost the
> generics information (even if the class sending it to you knows). So, for
> framework that want to use generics information, you need the class object
> that contain the generic member, and of course to identify the member
> (Annotation or Ugly strings).
> That's where erasure hits and gets painful for framework.
>
> Keep up with good suppositions :)
>
>
>
> On Mon, Nov 3, 2008 at 4:45 PM, Alexey Zinger <[EMAIL PROTECTED]> wrote:
>
> > In the discussion of the new Java decompiler that recognizes generics, the
> > guys seemed to be surprised that class files can retain that information and
> > were wondering why it's not in the reflection API. Without running a real
> > test to see what's actually available, the API are most certainly there:
>
> >http://java.sun.com/javase/6/docs/api/java/lang/reflect/GenericDeclar...
>
> > Alexey
> > 2001 Honda CBR600F4i (CCS)
> > 1992 Kawasaki EX500
> >http://azinger.blogspot.com
> >http://bsheet.sourceforge.net
> >http://wcollage.sourceforge.net
>
> --http://www.jfrog.org/http://freddy33.blogspot.com/http://nothingisinfinite.blogspot.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---