Forums Register Login

type casting Vs narrowing

+Pie Number of slices to send: Send
What is the difference betwen type casting and narrowing?
+Pie Number of slices to send: Send
What kind of answer were you able to find using Google or some other search engine? Did you not understand he answer and need a more detailed explanation?

Narrowing is a specific form of type casting that applies to primitive types (int to byte, double to float) instead of Objects (List to ArrayList, Object to Foo).
+Pie Number of slices to send: Send
Hi Kri,
Narrowing (explicit cast) means you want to shove something big into something small (float --> int) and you need to let the compiler know that your aware that there could be a "possible loss of precision". Widening (implicit cast) doesn't require you to write the cast, the conversion will happen automatically beacuse the compiler knows a byte value will fit inside an int .

Originally posted by kri shan:
What is the difference betwen type casting and narrowing?

 
Maybe he went home and went to bed. And took this tiny ad with him:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2929 times.
Similar Threads
Implicit and Explicit Casting
casting
byte to int ?
I've looked through the threads on casting to try to get my head wrapped around it.
Can i use the return values of finder method directly
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:22:00.