Howdy Xu,
welcome to the ranch!
perhaps you didn't get any answers to this posting by know because you typed:
conversion(reference types) behind <wantedType>
Maybe many people think you are speaking about
generic types because you used the <> brackets.
You need explicit assignment conversion (or casting) when you have a variable of a super class, you know that the object behing it is of a sub class (so more specific) and you now need one of the more specific methods of the subclasses.
Further:
And how can compiler know that here is a ClassCastException?
The compiler does not know this. Exceptions are occuring when you run the program, not when you are compiling your code.
Example with fish:
This code compiles, but when you run it you'll see a class cast exception at the end.
Output is:
I'm swimming
And I have got 3 stripes
Exception in thread "main" java.lang.ClassCastException: test.Shark
at test.Main.main(Mai .... And Xu also wrote:
i mean something like memory address changes..
You do not deal with memory adresses in Java. This is because Java is system independent, and memory adresses will be managed from the system dependent Java Virtual Machine. The adresses cannot be called from the code itself, because managing this adresses would be quite different on - say - a windows computer and a macintosh.
Hope that helped a bit.
Maybe have also a look on this campfire story:
http://www.javaranch.com/campfire/StoryPoly.jsp Yours,
Bu.
-- edit: added link --
[ January 27, 2008: Message edited by: Burkhard Hassel ]