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.
I think, your question is why the first one gives the type erasure related error while the first one does not. The answer is that when you compile the second code ie..
compiler generates the corresponding bite code as follows -
In this case, you can see that all the type information was erased and T was converted to Object.... Now think of the first code mentioned by you.. ie
In this case, you are using instance of operator on T. Java compiler did not give this as an option and declared this an error due to obvious reasons that converting (my instanceof T) to (my instanceof Object) after compilation would have confused many developers as they could have been doing it thinking a type safe operation but it wold have not been.
I hope this would clear all you confusion.
Joined: Oct 30, 2009
thanks salil....upto the point explaination.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com