Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Re: Generics for a multiplevalue hashmap (http://www.velocityreviews.com/forums/t751711-re-generics-for-a-multiplevalue-hashmap.html)

Richard 07-19-2011 08:32 PM

Re: Generics for a multiplevalue hashmap
 
Thanks for all your replies.

I have done this

public class MultipleValueHashMap<T, U> implements Map<T, java.util.List<U>> {

I want to implement Map rather than extend HashMap as per Josh Bloch's Effective Java item 16. http://java.sun.com/docs/books/effective/toc.html

So I do not want to do this.
public class MM2<T,U> extends HashMap<T, List<U>> {
}

Thanks for all your help. I will look into some of the other answers later in the week.

Many thanks
Richard

Arne Vajhøj 07-21-2011 09:15 PM

Re: Generics for a multiplevalue hashmap
 
On 7/19/2011 4:32 PM, Richard wrote:
> I have done this
>
> public class MultipleValueHashMap<T, U> implements Map<T, java.util.List<U>> {
>
> I want to implement Map rather than extend HashMap as per Josh Bloch's Effective Java item 16. http://java.sun.com/docs/books/effective/toc.html
>
> So I do not want to do this.
> public class MM2<T,U> extends HashMap<T, List<U>> {
> }



Note the word "favor".

You should evaluate not just choose without thinking.

Arne


lewbloch 07-21-2011 10:30 PM

Re: Generics for a multiplevalue hashmap
 
Arne Vajhøj wrote:
> Richard wrote:
>> I have done this

>
>> public class MultipleValueHashMap<T, U> * implements Map<T, java.util.List<U>> *{

>
>> I want to implement Map rather than extend HashMap as per Josh Bloch's Effective Java item 16.http://java.sun.com/docs/books/effective/toc.html

>
>> So I do not want to do this.
>> public class MM2<T,U> *extends HashMap<T, List<U>> * {
>> }

>
> Note the word "favor".
>
> You should evaluate not just choose without thinking.


At the very least, consider extending java.util.AbstractMap<K,V>.

--
Lew


All times are GMT. The time now is 03:03 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57