Even a chimp can write code

Tuesday, January 25, 2005

Questionable String.valueOf implementation

My obsession with Strings continues. I just came across an inexplicable anomaly in the java.lang.String class.

int[] numbers = null;
System.out.println(String.valueOf(numbers));

char[] characters = null;
System.out.println(String.valueOf(characters));

These two String.valueOf() method calls display different behavior. The former displays a "null" string. The latter, being rather quixotic, throws a NullPointerException. If there's a good reason for this divergence (I have a hunch there is), it isn't immediately apparent. Can someone please shed some light?

Email this | Bookmark this

1 Comments:

Post a Comment | Home | Inference: my personal blog