>As I understand it, no generics info gets carried forward to runtime
java.lang.reflect.Method has these methods in Java5:
getGenericExceptionTypes
getGenericParameterTypes
getGenericReturnType
Java.lang.reflect.Field has this method in Java5:
getGenericType
It seems to me everything is available at runtime, but I haven't
actually used those methods myself yet.
The methods you mention return the actual declared type in the source code,
eg.
public class List<T> {
add(T element);
}
... would return reflectiion info that describes the generic type T (since T
is not actually a real class but a placeholder for a compile time class when
this class is used).
But if you created an instance of that class at runtime thusly:
List<String> strings = new List<String>();
...then reflection would not be able to tell you that the instance you
created was intended to hold Strings. This is what is meant by erasure (the
type info gets erased at compile time). This ensures that, for instance,
that java.util.collection classes can be used in both forms, ie.
List strings = new ArrayList();
List<String> strings = new ArrayList<String>();
which will not break old code running in a java5 VM.
-Scott
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]