Hi,
I have a doubt on the advantage of Generics over the Non-Generic version.
Source :
http://java.sun.com/docs/books/tutorial/java/generics/QandE/generics-answers.html
In both Versions, Media is to be defined as an interface along with the Book, Video and Newspapers as the sub-interfaces.
In the
Non-Generic Version,
- We have to check the type of the argument resource "Media" before adding any resources to the List resources,
which will throw a compile time error, if add(Media x) is called with any other incompatible argument.
In the
Generic Version,
- We have the check "E extends Media" which will help to detect compile time error avoiding run-time exceptions due to incompatible types.
Also, the interface Media with the sub-interfaces will have to be defined in both versions.. then how is the non-generic version helpful!!!
I have read the tutotrial (link shown above) and I fail to understand, the advantage of using genric-version over non-generic one for this example.. can somebody please explain this one....
Tanya.