I'm very new on Java. I'd appreciate it if your answers considering this situation.
I have question, I want to develop a programme about extend the hashmap to add putchildren method. I wrote something.
My question is :
The task is extending the HashMap to include HashMaps as an object. so, this inner hashMap can also have key value pairs. It will be like tree with depth 2 . When you finish the method data
Key1 = "RUBY" value=HashMap which has -> "key2" = 5248 && "VALUE" = German
Key1 = "PYTHON" value=HashMap which has -> "key2" = 1234 && -> "VALUE" = German
you will implement a putChildrenValue method with 3 parameters, String key, String key, Object Value. It will store the system as described above accordingly.
My code is:
public class ExtHashMap<K1, K2, V> extends HashMap<K1, HashMap<K2, V>>
{
private static final long serialVersionUID = 1L;
public ExtHashMap() {
super();
}
public void putChildrenValue(K1 key1, K2 key2, V value) {
HashMap<K2, V> childMap = get(key2);
if (childMap == null) {
childMap = new HashMap<K2, V>();
put(key1, childMap);
}
childMap.put(key2, value);
}
}
And I run the code, after select Run as Java Application, Eclipse say= "Selection does not contain a main type"