Question : Set Java Class toString name?

Hello,

1:
2:
Class testClass = Test.class;
System.out.println(testClass);


How can I change what is printed out in the second line of this code? With an object, I would just override the toString() method. But how can it be done with a class?

Thanks,

Rich

Answer : Set Java Class toString name?

you can call it toString() if you like, eg.

public static String toString(Class clazz) {
   return clazz.getName();
}




System.out.println(MyUtility.toString(testClass));
Random Solutions  
 
programming4us programming4us