File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes type casting   Vs    narrowing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "type casting   Vs    narrowing" Watch "type casting   Vs    narrowing" New topic
Author

type casting Vs narrowing

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1368
What is the difference betwen type casting and narrowing?
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
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).
Trevor Whitehead
Greenhorn

Joined: Oct 16, 2002
Posts: 16
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?
 
Consider Paul's rocket mass heater.
 
subject: type casting Vs narrowing
 
Similar Threads
byte to int ?
Implicit and Explicit Casting
I've looked through the threads on casting to try to get my head wrapped around it.
casting
Can i use the return values of finder method directly