我在ideone.com中看到以下代码:
import java.util.*;
class Test{
interface Visitor{
public <T> void visit(T Value);
}
class MyVisitor<T> implements Visitor{
List<T> list = new ArrayList<T>();
public <T> void visit(T value){
list.add(value);
}
}
}
Run Code Online (Sandbox Code Playgroud)
编译时,此代码将产生以下+错误:
Main.java:12: error: no suitable method found for add(T#1)
list.add(value);
^
method List.add(int,T#2) is not applicable
(actual and formal argument lists differ in length)
method List.add(T#2) is not applicable
(actual argument T#1 cannot be converted to T#2 by method invocation conversion) where T#1,T#2 are type-variables:
T#1 extends …