Close

Java Reflection - Class.getTypeName() Examples

Code Snippets Java Reflection Java 


Class:

java.lang.Class

java.lang.Objectjava.lang.Objectjava.lang.Classjava.lang.Classjava.io.SerializableSerializablejava.lang.reflect.GenericDeclarationGenericDeclarationjava.lang.reflect.TypeTypejava.lang.reflect.AnnotatedElementAnnotatedElementLogicBig

Method:

public String getTypeName()
Returns:
an informative string for the name of this type

Examples


package com.logicbig.example.clazz;

public class GetTypeNameExample {

public static void main(String... args) {
Class<GetTypeNameExample> c = GetTypeNameExample.class;
System.out.println("TypeName: " + c.getTypeName());
System.out.println("Name: " + c.getName());
System.out.println("SimpleName: " + c.getSimpleName());
System.out.println("CanonicalName: " + c.getCanonicalName());
}
}

Output

TypeName: com.logicbig.example.clazz.GetTypeNameExample
Name: com.logicbig.example.clazz.GetTypeNameExample
SimpleName: GetTypeNameExample
CanonicalName: com.logicbig.example.clazz.GetTypeNameExample




package com.logicbig.example.clazz;

public class GetTypeNameExample2 {

public static void main(String... args) {
System.out.println("-- int[] --");
Class<int[]> c = int[].class;
System.out.println("TypeName: " + c.getTypeName());
System.out.println("Name: " + c.getName());
System.out.println("SimpleName: " + c.getSimpleName());
System.out.println("CanonicalName: " + c.getCanonicalName());

System.out.println("-- Integer[] --");
Class<Integer[]> c2 = Integer[].class;
System.out.println("TypeName: " + c2.getTypeName());
System.out.println("Name: " + c2.getName());
System.out.println("SimpleName: " + c2.getSimpleName());
System.out.println("CanonicalName: " + c2.getCanonicalName());

}
}

Output

-- int[] --
TypeName: int[]
Name: [I
SimpleName: int[]
CanonicalName: int[]
-- Integer[] --
TypeName: java.lang.Integer[]
Name: [Ljava.lang.Integer;
SimpleName: Integer[]
CanonicalName: java.lang.Integer[]




package com.logicbig.example.clazz;

public class GetTypeNameExample3 {

public static void main(String... args) {
Class<Void> c = void.class;
System.out.println("TypeName: " + c.getTypeName());
System.out.println("Name: " + c.getName());
System.out.println("SimpleName: " + c.getSimpleName());
System.out.println("CanonicalName: " + c.getCanonicalName());
}
}

Output

TypeName: void
Name: void
SimpleName: void
CanonicalName: void




See Also