Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Byte

 
Sireesha Mullapudi
Ranch Hand
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


why the line Byte b=new Byte("10L"); throwing NumberFormatException.

It is possible to cast long to byte.

then why Byte b=new Byte("10"); is not throwing Exception

Thanks,
SCJP1.4
 
Henry Wong
author
Marshal
Pie
Posts: 20835
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by lakshmi amulya:
Hi,

why the line Byte b=new Byte("10L"); throwing NumberFormatException.

It is possible to cast long to byte.

then why Byte b=new Byte("10"); is not throwing Exception

Thanks,
SCJP1.4


You are not casting a long to a byte -- nor casting a int to a byte. You are passing a string to the Byte class to parse to a byte. The "L" character is not supported by the parser called by the Byte class.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic