This post originated from an RSS feed registered with Java Buzz
by dion.
Original Post: Encapsulating Generic Types
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
I am a little scared of Generics (as you may have noticed).
I see some value, but I also see two problems:
Some programmers don't/won't get it
Holy readability batman!
As a way to help readability, AND to allow you to make changes to your codebase easier, I think it is often wise to encapsulate your Generic types.
Cedric did this very thing.
This is very ugly isn't it?
Map<String, List<Account>> accounts = new HashMap<String, List<Account>>();
So encapulate:
class AccountMap extends HashMap<String, List<Account>> {
...
}
Not only is it nicer to work with in your code now, but you can add functionality to the AccountMap if it makes sense. And all of your code gets the new functionality.