I have some work code whereby using generics has started to make the code look more confusing than it should.
Is it possible that I do away with generics and use interfaces for member types, constructor types, method parameter types and method return types?
What would generic provide, that the above using interfaces would not? I understand generics does compile-time checking when retrieving elements (to stop wrong casting- like in the old days), but wouldnt the compiler detect if I tried inserting types which were not a sub type of the interface required?
Generics makes the Collections more type safe.
If there is an extensive use of Collections in your working code, i will prefer sticking with
the generics.
And moreover as the infamous proverb states, “program in Interface, not in implementation”, Interface is moreover for flexibility than type safety.
Generics are also used for Class, method , interfaces, variables, constructor. etc….
See these link for more details :
http://en.wikipedia.org/wiki/Generics_in_Java
http://www.oracle.com/technetwork/articles/javase/generics-136597.html