Atom Feed SITE FEED   ADD TO GOOGLE READER

Java Minutiae - Class.toString()

Class.toString() doesn't return what you'd expect:
  assertEquals("java.lang.Integer", Integer.class.toString());

Instead, it prefixes the fully-qualified classname with "class " for classes, "interface " for interfaces and probably "enum " and "annotation " elsewhere. You need to call getName or getSimpleName() to get what you usually want.
  assertEquals("java.lang.Integer", Integer.class.getName());
assertEquals("Integer", Integer.class.getSimpleName());

What can I learn from this? The toString() value is important to the usability of an API. With toString, it's often better to be terse rather than complete.
You don't need toString in the last two lines, right?
I never thought too much about this, but perhaps a good toString() guideline is to think "how would this look in a debugger". Because a concise string representation is a lot better than an ugly @ with hex characters.

Or for UI developers, to consider "how would this look if I used it in a list, table or tree", meaning the default toString() should probably return a concise, simple value.
Kirill - fixed.

Eric - "How would this look in a table" is a great rule of thumb. I'm going to remember that.