I know genric class can take different types. But for some daily projects, I still don't see this feature is quite useful. For example, if I have a typical eShopping cart project, I need to show customer the list of products with details, allow customers to pick and order, on the backend I maintain SQL server database to keep updating the inventory and other tables when customers order things. I don't see where I can take advantage of generic class feature for such a common real project ? Any thought ?
Using generics to specify types in a collection is a convenience feature when you use specifics, ie:
This is what I call a "consumer" of Java generics.
On the other hand, generics allow you to perform type-based logic where type is not known until runtime.
Lets say you have a specific type of product that you wish to remove from your collection - you could write a specific method that removes all "Gift" objects from the collection, or you could write a method that would allow you to remove whatever type the method caller wishes:
Type information is maintained, and you get the Gift objects out of the list.