Close

Java Reflection - Class.toString() Examples

Java Reflection Java Java API 


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 toString()
Returns:

A string representation of this class object. The string representation is the string "class" or "interface", followed by a space, and then by the fully qualified name of the class in the format returned by getName(). If this Class object represents a primitive type, this method returns the name of the primitive type. If this Class object represents void this method returns "void".


Examples


package com.logicbig.example.clazz;

public class ToStringExample {

public static void main(String... args) {
String s = String.class.toString();
System.out.println(s);
}
}

Output

class java.lang.String




package com.logicbig.example.clazz;

public class ToStringExample2 {

public static void main(String... args) {
String s = Runnable.class.toString();
System.out.println(s);

s = Deprecated.class.toString();
System.out.println(s);
}
}

Output

interface java.lang.Runnable
interface java.lang.Deprecated




package com.logicbig.example.clazz;

public class ToStringExample3 {

public static void main(String... args) {
String s = int.class.toString();
System.out.println(s);

s = int[].class.toString();
System.out.println(s);

s = void.class.toString();
System.out.println(s);
}
}

Output

int
class [I
void




See Also