Java Reflection - Class.getName() 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 getName()
Returns:
the name of the class or interface represented by this object.

Examples


package com.logicbig.example.clazz;

public class GetNameExample {

public static void main(String... args) {
Class<GetNameExample> c = GetNameExample.class;
String name = c.getName();
System.out.println(name);
}
}

Output

com.logicbig.example.clazz.GetNameExample




package com.logicbig.example.clazz;

public class GetNameExample2 {

public static void main(String... args) {
Class<Integer> c = int.class;
String name = c.getName();
System.out.println(name);

Class<int[]> c2 = int[].class;
String name2 = c2.getName();
System.out.println(name2);

Class<Void> c3 = Void.class;
String name3 = c3.getName();
System.out.println(name3);

Class<Void> c4 = void.class;
String name4 = c4.getName();
System.out.println(name4);
}
}

Output

int
[I
java.lang.Void
void




See Also