This question already has an answer here:
Q: Why does the name of the containing class appear twice?
Context: I'm generating code and the goal is to get the declaration of the field, as written in the source (fully qualified is fine, but I need the type parameter): test.Foo.Bar<java.lang.String>
package test;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
public class Foo
{
public static class Bar<TYPE> {}
private Bar<String> bar;
public static void main(String[] args) throws Exception
{
Field field = Foo.class.getDeclaredField("bar");
Type genericType = field.getGenericType();
Type type = field.getType();
System.out.println("genericType: " + genericType.getTypeName());
System.out.println(" type: " + type.getTypeName());
}
}
Output:
genericType: test.Foo.test.Foo$Bar<java.lang.String>
type: test.Foo$Bar
UPDATE: Thank you everyone for your input. Since this question was marked as duplicate, I posted my current working solution over there.
genericType is instance of ParameterizedTypeImpl
the toString() method returns ownerType class' name and then rawType classname.
The decompiled piece of the code