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:
Java
Java
public String toGenericString()Parameters: This method accepts nothing. Return: This method returns a generic form of this constructor as a string that describes this Constructor along with the type parameters. Below programs illustrate toGenericString() method: Program 1:
// Java program to illustrate
// toGenericString() method
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
public class GFG {
public static void main(String[] args)
{
// create a class object
Class classObj = shape.class;
// get Constructor object
// array from class object
Constructor[] cons = classObj.getConstructors();
// check get string representation
String str = cons[0].toGenericString();
// print result
System.out.println("Constructor : " + str);
}
public class shape {
public shape(Object... objects)
{
}
}
}
Output:
Program 2:
Constructor : public GFG$shape(GFG, java.lang.Object...)
// Java program to illustrate
// toGenericString() method
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
public class GFG {
public static void main(String[] args)
{
// create a class object
Class classObj = String.class;
// get Constructor object
// array from class object
Constructor[] cons
= classObj.getConstructors();
for (int i = 0; i < cons.length; i++) {
String str = cons[i].toGenericString();
// print result
System.out.println(str);
}
}
}
Output:
References: https://docs.oracle.com/javase/10/docs/api/java/lang/reflect/Constructor.html#toGenericString()public java.lang.String(byte[], int, int) public java.lang.String(byte[], java.nio.charset.Charset) public java.lang.String(byte[], java.lang.String) throws java.io.UnsupportedEncodingException public java.lang.String(byte[], int, int, java.nio.charset.Charset) public java.lang.String(byte[], int, int, java.lang.String) throws java.io.UnsupportedEncodingException public java.lang.String(java.lang.StringBuilder) public java.lang.String(java.lang.StringBuffer) public java.lang.String(byte[]) public java.lang.String(int[], int, int) public java.lang.String() public java.lang.String(char[]) public java.lang.String(java.lang.String) public java.lang.String(char[], int, int) public java.lang.String(byte[], int) public java.lang.String(byte[], int, int, int)