Forums Register Login

Cast compiler error

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
yes. And please quote your sources from now on
+Pie Number of slices to send: Send
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
Or we might never have existed at all. Freaky. So we should cherish everything. Even this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 951 times.
Similar Threads
small doubt in declaration
Quick question about casting
why compilation fails here
Casting????
small doubt in declaration
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:59:39.