nolacoaster ([info]nolacoaster) wrote,
Hmm... good point. I'll probably add this. Here's what I cooked up:

static <K,V> Map<K,V> mapMe(Pair<K,V>... pairs) {
  Map<K,V> result = new HashMap<K,V>();
  for( Pair<K,V> pair : pairs) {
    result.put(pair.getP1(), pair.getP2());
  }
  return result;
}


static void useMapMe() {
  Map<Integer,String> myMap = mapMe( Pair.pairMe(1, "Nels"),
                                     Pair.pairMe(2, "William"));		
}


This does have one problem though; it returns a Java Generics warning at the use of mapMe, "Type safety : A generic array of Pair<Integer,String> is created for a varargs parameter."


Advertisement


(Read 11 comments)

Post a comment in response:

From:
Help
Identity URL: 
Username:
Password:
Don't have an account? Create one now.
Subject:
No HTML allowed in subject
   Help
Message:
 
Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…