When I use System.out.println(obj.getClass()) it doesn\'t give me any error. From what I understand getClass() returns a Class type.
Since p
System.out.println(someobj) is always equivalent to:
System.out.println(String.valueOf(someobj));
And, for non-null values of someobj, that prints someobj.toString();
In your case, you are doing println(obj.getClass()) so you are really doing:
System.out.println(String.valueOf(obj.getClass()));
which is calling the toString method on the class.