Cannot infer type arguments for ArraySortedMap<>

Kev :

I have an assignment regarding generics. -jdk.13.02, Eclipse.

Map<String, Person> personByFirstName = new ArrayMap<>();

This line of code gives me the error: "cannot infere type arguments for ArrayMap"

this is the header of the Interface Map:

public interface Map<K, V> extends Iterable<Map.Entry<K, V>>

this is the class ArrayMap:

public class ArrayMap <K, V> implements Map<K, V>{
    @SuppressWarnings("unchecked")
    protected Entry<K, V>[] array = (Entry<K, V>[]) new Entry[16];
    protected int nEntries = 0;

    ArrayMap(){

    }

... etc. The @suppresswarnings was required as per the assignment.

Does anyone has an idea what could be going on here or is it not enough information? I am just guessing that the problem lies in the class headers/ generics. I tried googling the error and other things but have not found anything.

Thanks

Алексей Долгов :

Your code works fine for me:personbyfirst name declaration

Heres the same arraymap you have. So id guess you either implemented a method in a broken way or messed up an import. Try to make a new project with the same code.

import java.util.Collection;
import java.util.Map;
import java.util.Set;

public class ArrayMap <K, V> implements Map<K, V> {
    @SuppressWarnings("unchecked")
    protected Entry<K, V>[] array = (Entry<K, V>[]) new Entry[16];
    protected int nEntries = 0;

    ArrayMap(){

    }

    @Override
    public int size() {
        return 0;
    }

    @Override
    public boolean isEmpty() {
        return false;
    }

    @Override
    public boolean containsKey(Object key) {
        return false;
    }

    @Override
    public boolean containsValue(Object value) {
        return false;
    }

    @Override
    public V get(Object key) {
        return null;
    }

    @Override
    public V put(K key, V value) {
        return null;
    }

    @Override
    public V remove(Object key) {
        return null;
    }

    @Override
    public void putAll(Map<? extends K, ? extends V> m) {

    }

    @Override
    public void clear() {

    }

    @Override
    public Set<K> keySet() {
        return null;
    }

    @Override
    public Collection<V> values() {
        return null;
    }

    @Override
    public Set<Entry<K, V>> entrySet() {
        return null;
    }
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=403193&siteId=1