Subsequent characters may be letters, digits, dollar signs, or underscore characters.
Henry Wong wrote:
kevinn lee wrote:
why doesnt line 1 one causes a runtime exception while line 2 does?
The answer to "why" is probably lost in the bowels of history -- ie. I doubt if anyone knows. These are merely two different implementations. The Float implementation seems more robust, can deal with extra whitespaces, and follows the same definition of floating point as the JLS. However, the Long implementation seems to be less robust, and can only take digits -- no white space, no leading zero for octal, no hexidecimal syntax, etc.
Maybe they were done at different times. Maybe they were done by two different developers. Etc. Your guess would probably be as good as mine.
Henry
Jim Hoglund wrote:The string pool mechanism is at work here. To conserve memory, the compiler will
at times, share a string object if sX.equals(sY). Apparently in your case it put "abc" in
the pool and used it again. (Maybe for s1, s3 and s4).)
Jim ......
Sandra Bachan wrote:Hello,
Ravinderjit Singh wrote:Because will create a new String object, means s1 and s3 are referring to two different objects.
String s3=s2+"c";