Here are examples of parsing String literal representations of numeric literals with suffixes. Why does parsing a float from 1f and 1d work, but parsing a float from 1L fail and parsing bytes from 1L, 1f and 1d all fail?
The parse functions of the wrapper classes require that the input string be parseable text that is equivalent to the corresponding primitive. You couldn't actually assign a double, long, or float to a byte, so why should Byte let you do it via a String? [ August 24, 2005: Message edited by: Ryan Kade ]
Joined: Aug 22, 2005
I guess I was expecting a different error message since the String is technically parsable as a number.
Still you're right. Those assignments can't be made without an explicit cast.
Joined: Aug 16, 2005
True, the strings are technically parseable as a number, but that's not what the contract specifies.
The SDK docs for Integer.parseInt say an exception is thrown if "The value represented by the string is not a value of type int." You'll find similar language in each of the wrapper class docs.