For a homework assignment which is stated as:
In this homework, you will implement a key-value hash map with a external chaining collision policy. A hash map maps keys to values and allows O(1) average case lookup of a value when the key is known. This hash map must be backed by an array of initial size 11, and must have a size of 2n + 1 when the table exceeds (greater than, not greater than or equal to) a load factor of 0.67. The array must be resized before the new key (regardless of whether or not it's a duplicate) is actually added into the array. The load factor and initial size values are provided as constants in the interface and should be used within your code.
We're given a MapEntry class already written, and a HashMap class to write up. How would I intialize this array? private MapEntry<K, V>[] table = new MapEntry<>[STARTING_SIZE];
doesn't work because of the generics situation.
You omit the generic parameters in the array constructor:
Map.Entry<String,Integer>[] entries = new Map.Entry[11];
You can use an annotation @SuppressWarnings("unchecked")
if the warning bothers you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.