• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

type casting Vs narrowing

 
kri shan
Ranch Hand
Posts: 1460
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference betwen type casting and narrowing?
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic