Results 1 to 4 of 4
Thread: What does casting mean?
- 01-26-2009, 08:13 PM #1
Member
- Join Date
- Jan 2009
- Posts
- 7
- Rep Power
- 0
- 01-26-2009, 09:05 PM #2
you got it, its converting one data type to another.
all classes are child classes of java.lang.Object, so you can freely cast any class to Object class, or any class within the same family.USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 01-26-2009, 11:34 PM #3
Member
- Join Date
- Jan 2009
- Posts
- 7
- Rep Power
- 0
Thanks for the confirmation :)
- 01-27-2009, 04:31 PM #4
Casting is used when you, as the developer, have a reference to an object of type ClassA, but you know that the object type is actually of type ClassB, where ClassB extends ClassA.
This comes into play for generic methods that return Object. You want to invoke methods of the actual type, so you have to explicitly cast the Object to MyClass. Essentially, you are telling the compiler you know what you are doing.
At runtime, if the Object is *not* a MyClass, you will get a RunTimeException.
Similar Threads
-
casting help
By soc86 in forum New To JavaReplies: 4Last Post: 01-13-2009, 11:07 PM -
Object to Int casting
By nn12 in forum New To JavaReplies: 4Last Post: 12-06-2008, 10:58 PM -
type casting
By alvations in forum New To JavaReplies: 1Last Post: 10-13-2008, 07:07 PM -
'Casting' couch !!!!
By ajaygargnsit in forum Advanced JavaReplies: 4Last Post: 01-04-2008, 04:54 PM -
Casting
By leebee in forum New To JavaReplies: 5Last Post: 08-10-2007, 12:24 PM
Bookmarks