以前从未使用过 Java 并尝试在类中实现接口:
界面:
public interface TestInterface<E> {
public void doSomething(E elem);
}
班级:
public class TestClass implements TestInterface<E> {
public static void main() {
// ...
}
public void doSomething(E elem) {
// ...
}
}
当我运行 javac 编译器时。我收到这些错误:
TestClass.java:5: cannot find symbol
symbol: class E
public class TestClass implements TestInterface<E> {
^
TestClass.java:11: cannot find symbol
symbol : class E
location: class TestClass
public void doSomething(E elem) {
^
如果我用“String”替换所有“E”,它会起作用,但我希望它使用泛型类型。我该怎么做呢?