Avn,
Take a look at Vector API, you would see that lastElement returns an Object, so one clear use for this method would be:
In this case you cast an Object type to Float type. The compiler does not complain because Float "is_a" Object. At run time, there is no problem because you did put an Float object into Vector. You know this but the compiler doesn�t, so you need cast as (Float).
Thanks for ur reply Andrian.But i am not clear with it. Do u mean to say that a Float Object value cannot be directly typecasted using Integer.Then it shouldnt it be
See that here you are casting an Object, that is returned from lastElement(), to Integer. So, there should be no problem at compile time but it doesn�t run well since a Float is not ("is_a"" is not valid) an Integer object. To be short, type is checked at compile time but in
Java, each object knows what class it is an "instanceof" and it is checked at run time.
Hope to help you.