This is something I should know, but I’m drawing a blank on it and am having a surprising amount of difficulty trying to find the answer with google.
I’m trying to extend a Java Collection, specifically the ConcurrentHashMap. I want to create my own hash map class for use with non-generic key/value pairs, specifically using my own classes.
So I’ve defined the class as such:
public class hashMap extends ConcurrentHashMap<class1, class2>
The issue is I’m forgetting how to properly write the constructor(s) so that they’re non-generic. For instance, with the original concurrentHashMap, you have to call its constructor specifying the classes for the key/value pairs. I want to just simply be able to call the constructor hashMap(), without needing to specify those generics.
I’ve tried calling super<class1, class2>(); in the constructor, but that gave me an error.
This seems like it should be something very simple, and I’m positive I used to know how to do this, but it’s been a while and like I said I’m drawing a blank.
Thanks.
Just plain
super();will work—or nothing at all, since it is implied. Remember thatnew HashMap<String,Integer>();is not really a constructor invocation in the same sense of a method invocation: it is the specification of the type to instantiate + constructor arguments. The constructor itself does not receive the type arguments, they are there only as call-site type information.