Answers for "how to get class object in java"

1

how to find the class of an object java

// obj instanceof Class

/*example*/

String str = "a String made by the String class";

if(str instanceof String) System.out.println("This is True");
if(str instanceof float) System.out.println("This will never be on your screen");
Posted by: Guest on November-22-2020
0

how to use getclass in java

public static String printClassInformation(Object o){
	Class<?> cl=o.getClass();
  	System.out.println("Name: "+cl.getSimpleName());
  	System.out.println("Full name: "+cl.getCanonicalName());
  	System.out.println("Methods: "+Arrays.toString(cl.getMethods()));
}
Posted by: Guest on April-06-2021

Code answers related to "how to get class object in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language