Class toGenericString() method in Java with Examples Last Updated : 27 Nov, 2019 Comments Improve Suggest changes Like Article Like Report The toGenericString() method of java.lang.Class class is used to convert the instance of this Class to a string representation along with the information about the modifiers and type parameters. This method returns the formed string representation. Syntax: public String toGenericString() Parameter: This method does not accept any parameter. Return Value: This method returns the String representation of this object. Below programs demonstrate the toGenericString() method. Example 1: Java // Java program to demonstrate toGenericString() method public class Test { public static void main(String[] args) throws ClassNotFoundException { // returns the Class object for the class // with the specified name Class c1 = Class.forName("java.lang.String"); System.out.print("Class represented by c1: "); // toGenericString method on c1 System.out.println(c1.toGenericString()); } } Output: Class represented by c1: public final class java.lang.String Example 2: Java // Java program to demonstrate toGenericString() method public class Test { public static void main(String[] args) throws ClassNotFoundException { // returns the Class object for the class // with the specified name Class c2 = int.class; Class c3 = void.class; System.out.print("Class represented by c2: "); // toGenericString method on c2 System.out.println(c2.toGenericString()); System.out.print("Class represented by c3: "); // toGenericString method on c3 System.out.println(c3.toGenericString()); } } Output: Class represented by c2: int Class represented by c3: void Reference: https://docs.oracle.com/javase/9/docs/api/java/lang/Class.html#toGenericString-- Comment More infoAdvertise with us Next Article Class toGenericString() method in Java with Examples S srinam Follow Improve Article Tags : Java Java-lang package Java-Functions Java.lang.Class Practice Tags : Java Similar Reads Class toString() method in Java with Examples The toString() method of java.lang.Class class is used to convert the instance of this Class to a string representation. This method returns the formed string representation. Syntax: public String toString() Parameter: This method does not accept any parameter. Return Value: This method returns the 1 min read Constructor toGenericString() method in Java with Examples The toGenericString() method of java.lang.reflect.Constructor class is used to return get the generic form of this constructor, i.e. a string representing the details about this constructor including the type parameters. Syntax: public String toGenericString() Parameters: This method accepts nothing 2 min read Field toGenericString() method in Java with Examples The toGenericString() method of java.lang.reflect.Field is used to return a string which represents this Field, including its generic type. The format of the string is the access modifiers for the field, if any, followed by the generic field type, followed by a space, followed by the fully-qualified 2 min read Charset toString() method in Java with Examples The toString() method is a built-in method of the java.nio.charset returns a string which describes the charset involved. Syntax: public final String toString() Parameters: The function does not accepts any parameter. Return Value: The function returns a string describing this charset. Below is the 1 min read Calendar toString() Method in Java with Examples The toString() method in Calendar class is used to get the string representation of the Calendar object. This method in Calendar Class is just for debug process and not to be used as an operation. Syntax: public String toString() Parameters: The method does not take any parameters. Return Value: The 1 min read Like