Java Quiz

Suche elegante Möglcihkeit das untenstehende Idiom in generischer Form zu implementieren, da ich insbesondere das put gerne vergesse. Any Ideas?

map = ....;

//probably a loop here:
key = ....;

Element element;
if (map.containsKey(key)){
    element=(Element)map.get(key);
}
else{					 
    element=new Element();
    map.put(key,element);
}
//work with element
This entry was posted in Java, Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *