Java 无法解析原始类型/T

Java 无法解析原始类型/T,java,generics,compiler-errors,Java,Generics,Compiler Errors,我开始使用Java泛型,但似乎缺少一个关键组件 首先,我阅读了一些关于需要参数的原始类型的内容,并意识到由于它们是泛型的,所以没什么可做的,但我的问题是BagInterface和LinkedBag之间的交互: package Chapter3; public interface BagInterface<T> { /** Gets the current number of entries in the bag. * @return the integer number of e

我开始使用Java泛型,但似乎缺少一个关键组件

首先,我阅读了一些关于需要参数的原始类型的内容,并意识到由于它们是泛型的,所以没什么可做的,但我的问题是
BagInterface
LinkedBag
之间的交互:

package Chapter3;

public interface BagInterface<T> {

/** Gets the current number of entries in the bag.
* @return the integer number of entries in the bag. */
public int getCurrentSize();

/** Sees whether this bag is full.
*@return true if the bag is full, or false if not. */
public boolean isFull();

/** Sees whether the bag is empty.
*@return true if bag is empty, or false if not. */
public boolean isEmpty();

/** Adds new entry to this bag.
*@param newEntry the object to be added as a new entry
*@return if the addition was successful, or false if not. */
public boolean add(T newEntry);

/** Removes one unspecified entry from this bag, if possible.
*@return either the removed entry, if the removal was successful, or null. */
public T remove();

/** Removes one occurrence of a given entry from this bag.
*@param anEntry the entry to be removed
*@return true id the removal was successful, or false if not. */
public boolean removal(T anEntry);

/** Removes all entries from this bag. */
public void clear();

/** Counts the number of times a given entry appears in this bag.
*@param anEntry the entry to be counted
*@return the number of times anEntry appears in the bag. */
public int getFrequencyOf(T anEntry);

/** Tests whether this bag contains a given entry.
*@param anEntry the entry to locate
*@return true if this bag contains anEntry, or false if not. */
public boolean contains(T anEntry);

/**Retrieves all entries that are in this bag.
*@return a newly allocated array of all the entries in the bag */
public T[] toArray();
}

我已经转录了完整的.java文件,以记录是否需要更多信息,但我试图保持其具体和简洁。

LinkedBag
在您共享的代码中,实现了原始
BagInterface
。如果您想引用它的类型规范,还应该向
LinkedBag
添加类型参数,并让它以某种方式引用
BagInterface
类型。例如:

public class LinkedBag<T>  implements BagInterface<T> { 
// Here --------------^---------------------------^
公共类LinkedBag实现BagInterface{
//这里--------------^---------------------------^

T上的错误无法解析为类型“errors on getData()”类型LinkedBag.Node中的方法getData()引用了缺少的类型“T”是什么行导致了此错误?public LinkedBag(T[]item,int numberOfItems){result[index]=currentNode.getData();在这个类中引用的任何地方,.getData()谢谢,我昨晚正在做这件事,撞到了墙,我正在工作,所以我无法测试它,但我会这样做,看看我的问题是否得到解决..我想也许我只是没有将这些类链接在一起,但它们存在于同一个包中(我对编译器的知识同样有限)这学期才开始使用eclipse
(error occurs here) result[index] = currentNode.getData();
index++;
currentNode = currentNode.getNextNode();
}// end while
return result;
}// end is full
public class LinkedBag<T>  implements BagInterface<T> { 
// Here --------------^---------------------------^