This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes how is Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "how is "castOther " object which is of type object gets casted to object bof Account type" Watch "how is "castOther " object which is of type object gets casted to object bof Account type" New topic
Author

how is "castOther " object which is of type object gets casted to object bof Account type

monis raza
Greenhorn

Joined: Sep 05, 2011
Posts: 21

Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 3862
    
    1

A cast (for a reference) doesn't convert the object. It will only work if the object in question is actually an Account object, and all it does is change the type of the reference.

What the cast does is tell the compiler "See that Object reference you've got? Well, it's actually pointing at an Account object. So please treat it as one".
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32830
    
    4
There are a few occasions where the compiler won’t believe youOtherwise the compiler is much more trusting than we are: it thinks you are telling it the truth, and that you know what you are doing.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: how is "castOther " object which is of type object gets casted to object bof Account type
 
Similar Threads
toString method in vector.
Hibernate Question
Program like ATM where person enters amount in dollars and cents but program uses int for monies
Hibernate Question
composite key and Criteria API [Hibernate]