This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Cast compiler error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cast compiler error" Watch "Cast compiler error" New topic

Cast compiler error

shuba gopal
Ranch Hand

Joined: May 12, 2011
Posts: 76
The following example results in a compiler exception and needs a cast to execute.

For primitives, I know that the result of arithmetic operations with byte and short result in int and need casting to avoid compiler errors. Number literals are by default int and hence in this example a cast is needed. Am I right?
jishnu dasgupta
Ranch Hand

Joined: Mar 11, 2011
Posts: 103

yes. And please quote your sources from now on

If debugging is the process of removing bugs, then programming must be the process of putting them in. -- Edsger Dijkstra

Unnar Björnsson
Ranch Hand

Joined: Apr 30, 2005
Posts: 164
giving a method expecting a short an int will cause compiler error because int which is a 32 bit 2's complement integer can cause overflow if it's stored in short which is only 16bit, however the reverse is ok, you can store short integer in int since int is an extension of short
Consider Paul's rocket mass heater.
subject: Cast compiler error
Similar Threads
why compilation fails here
small doubt in declaration
small doubt in declaration
Quick question about casting