This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
It doesn't mean that you can assign a object to a subtype without cast
see the code
This code won't comiple...
as method1() is returnig a String ( Sub class object of the Object Class) in actual,but method signature says it will return a Object type object
so returning value can't be assigned to Sub class object without downcast.
vijay saraf wrote:It doesn't mean that you can assign a object to a subtype without cast
Was this for me?? Well if yes, then I was just trying to say that direct assignment of a super type object to a sub-type reference will result in a compilation error. The code of option A will fail because the return type of the method is List as opposed to the reference in which it is assigned. Just merge the code and the option and everything will be crystal clear
Even if we forget generics, option A wont compile
Joined: Dec 06, 2008
Joined: Jan 08, 2005
NO...Ankit...i replied to Richa Only.
We both are saying the same thing.