For debugging purposes, I would like to display the type of a specific variable in Java, e.g.:
String s = "adasdas";
System.out.println( SOME_MAGIC_HERE(s) );
And get:
String
You're looking for the Object.getClass()
method.
Examples:
System.out.println(s.getClass()); // Prints "java.lang.String"
System.out.println(s.getClass().getSimpleName()); // Prints "String"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With