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

Posted

in

,

by

Tags:

Comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.