Как обращаться с необработанными типами и непроверенными предупреждениями? - PullRequest
0 голосов
/ 16 февраля 2019

Я пытаюсь реализовать универсальный HashTable.В моем коде у меня есть узлы в массиве.Я пытаюсь инициализировать размер моего массива в конструкторе по умолчанию с помощью моего общего класса Node.Я пытаюсь решить эти предупреждения без @SuppressWarnings

Я уже пробовал table = (Node<K,V>[]) new Object[capacity];, но получаю то же предупреждение:

Вот что у меня есть:

public class HashTable<K,V> implements Table<K,V>{

private static final int INIT_CAPACITY = 4;
private int n;
public int tableSize; 
public Node<K,V>[] table;

public HashTable(){
    this(INIT_CAPACITY);
}

public HashTable(int capacity){
    this.tableSize = capacity;
    this.n = 0;
    //table = (Node<K,V>[]) new Object[capacity]; // Also gives warnings
    table = (Node<K,V>[]) new Node[capacity]; // Warnings occur here
}

И мой общий класс узлов: открытый класс Node {

public K nodeKey; // key
public V nodeValue; // value
Node<K,V> next;


public Node(){

}

public Node(K key, V value, Node<K,V> next){
    this.nodeKey = key;
    this.nodeValue = value;
    this.next = next;
}


public K getKey(){
    return nodeKey;
}

public V getValue(){
    return nodeValue;
}

} 

Спасибо!Вот что я получаю при компиляции:

HashTable.java:17: warning: [rawtypes] found raw type: Node table = (Node<K,V>[]) new Node[capacity]; ^ missing type arguments for generic class Node<K,V> where K,V are type-variables: K extends Object declared in class Node V extends Object declared in class Node HashTable.java:17: warning: [unchecked] unchecked cast table = (Node<K,V>[]) new Node[capacity]; ^ required: Node<K,V>[] found: Node[] where K,V are type-variables: K extends Object declared in class HashTable V extends Object declared in class HashTable 2 warnings

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...