• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between casting and conversion in Java

 
nidhivel raja
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,
Can anyone please tell me what is the difference between Casting and Conversion in Java?Thank you in advance
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this to be a fairly good explanation.
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With casting, you are not modifying the object. The result of the cast is still the exact same object, just with a difference type of reference pointing to it:

With conversion, you are taking the source object and (in most cases) returning a new object based on the old one:
 
bob david
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
type casting , explaining with example :

roseindia.net/java/beginners/...

type conversion :

go4expert.com/forums/showthre...
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bob, can you please finish that second link? It doesn't point anywhere valid right now, and if I just go to the forum I have to do a search there. I might as well link to our own search.

And moving to beginners.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic