Constructor for a non-general subclass of a collection

This is what I should know, but I draw a space on it and I have amazing difficulty trying to find the answer using google.

I am trying to extend the Java Collection , specifically ConcurrentHashMap . I want to create my own hash map class for use with nonequivalent key / value pairs, in particular, using my own classes.

So, I defined the class as such:

 public class hashMap extends ConcurrentHashMap<class1, class2> 

The problem is that I forget how to write constructor (s) correctly so that they are nonequivalent. For example, with the original ConcurrentHashMap you must call its constructor, which defines the classes for the key / value pairs. I just want to just call the hashMap() constructor without specifying these generics.

I tried calling super<class1, class2>(); in the constructor, but that gave me an error.

It seems that this should be something very simple, and I'm sure I knew how to do it, but some time passed, and, as I said, I draw a space.

Thanks.

+4
source share
1 answer

Just plain super(); / mdash will work or nothing at all, as this is implied. Remember that new HashMap<String,Integer>(); is not a constructor call in the same sense as a method call: it is a type specification for instantiating + constructor arguments. The constructor itself does not receive type arguments ; they are available only in the form of site type information.

+6
source

All Articles