I have the following "working" static map:
private static final Map<String, Object[]> S_MAP;
static {
Map<String, Object[]> map = new HashMap<String, Object[]>();
map.put("somekey", new Object[] {"SSS", new Integer("6")});
map.put("bad", new Object[] {new Integer("6"), "VVV"});// s/b same as above
S_MAP = Collections.unmodifiableMap(map); }
The Object[]
I dislike. I have looked at inner class, but wondering how others would handle it. Inner class instantiation seems "odd".
So how would I change it so that String and Integer are compile time checked, since with Object[], anything goes.
The object is simply a string and integer. An inner class would require new Outerclass.new Innerclass("somestring",someint) additional, inner class would just be holding some values
public class SnI {
public String s;
public Integer i;
public SnI(....){
...}
}
Seemed overkill. But I suppose better than having an Object[] with casts.
Pair
is an anti-pattern. If the two elements belong together semantically, write a class and give it a proper name.Pair
is too generic. – Ingo Bürk Jul 2 '14 at 18:52