Quantcast
Channel: User rolfl - Stack Overflow
Viewing all articles
Browse latest Browse all 39

Answer by rolfl for Java. getClass() returns a class, how come I can get a string too?

$
0
0

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.


Viewing all articles
Browse latest Browse all 39

Latest Images

Trending Articles





Latest Images