Questionable String.valueOf implementation
My obsession with Strings continues. I just came across an inexplicable anomaly in the java.lang.String class.
These two String.valueOf() method calls display different behavior. The former displays a "null" string. The latter, being rather quixotic, throws a
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?
1 Comments:
This comment has been removed by a blog administrator.
By Ashish Shetty, at January 26, 2005 at 4:55 AM
Post a Comment | Home | Inference: my personal blog