I want to create a subclass of class of java.util.TreeMap, to allow me to add an increment method:
public class CustomTreeMap<K, V> extends TreeMap<K, V> {
public void increment(Integer key) {
Integer intValue;
if (this.containsKey(key)) {
Object value = this.get(key);
if (!(value instanceof Integer)) {
// Fail gracefully
return;
} else {
intValue = (Integer) value;
intValue++;
}
} else {
intValue = 1;
}
this.put(key, intValue); // put(Integer, Integer) cannot be applied in TreeMap
}
}
Android Studio 1.0.2 first proposes put(K Key, V Value)
for autocompletion, and later warns that:
put(K, V) cannot be applied in TreeMap to (java.lang.integer, java.lang.integer)
What is it that I am doing wrong?
See here for the solution I adopted.