为什么要编译?
B在A中使用,没有任何通用参数,这是用Java编译的。这是怎么回事?
interface B<T>
{
public T Foo(T value);
}
public class A
{
public B What()
{
return null;
}
public void Foo()
{
B x = What();
x.Foo(123);
}
}
答案 0 :(得分:8)
这是为了与J2SE 5.0之前的Java兼容。你应该得到一个rawtypes警告(注意编译器警告)。
答案 1 :(得分:7)
您只是在这里使用raw
类型的B
。就像
List list = new ArrayList(); // defined as: public interface List<E>
完美,有效;不推荐。