• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Type Casting Issue

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Will byte b = 127 compile?
Kathy Sierra Book says yes java 127 will be implicitly cast to byte.

But the program gave compilation error when I used Eclipse and JDK6.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes the program will compile. The value 127 is in the range of byte datatype so there will be an implicit type cast. How can eclipse give a compilation error with this ...
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But the program gave compilation error when I used Eclipse and JDK6.



Also, what is the compile error message that you are getting?

Henry
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Richa Sharma wrote:Will byte b = 127 compile?
Kathy Sierra Book says yes java 127 will be implicitly cast to byte.

But the program gave compilation error when I used Eclipse and JDK6.


As Ankit said, it should compile, as 127 is still in range of byte.
Eclipse compiler is buggy in some aspects, although such a simple case as above should be no problem. To get "standard" results, compile and run from command line. My experience is that IDE's compilers (not only Eclipse) aren't something you should fully rely on.

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...or reinstall eclipse. Mine compile this just fine.
 
Richa Sharma
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Guys
 
reply
    Bookmark Topic Watch Topic
  • New Topic