| Author |
Wrapper Classes
|
Saumya Tangeda
Greenhorn
Joined: Jul 09, 2006
Posts: 24
|
|
Why does the expression: new Short(1); causes a compile-time error while the expression: new Short("1"); does not?
|
 |
Saumya Tangeda
Greenhorn
Joined: Jul 09, 2006
Posts: 24
|
|
|
Sorry, the first expression is resulting in run-time error NOT compile-time error.I understand why, but i don't get why the second one is OK.
|
 |
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
|
|
No, the first one results in a compile-time error. There is no constructor in Short.java that accepts an int.
|
 |
Buhi Mume
Greenhorn
Joined: Jul 16, 2006
Posts: 17
|
|
By default, the number in new Short(1) is of type int. Thus, it produces compile error.
|
 |
 |
|
|
subject: Wrapper Classes
|
|
|