java泛型的一个错误求解
对于如下代码为什么eclipse会提示:K cannot be resolved to a type
public class GenericTest<T>
{
private Generic3<K> foo1 ;
public Generic3<K> getFoo1()
{
return foo1;
}
public void setFoo1(Generic3<K> foo1)
{
this.foo1 = foo1;
}
public static void main(String[] args)
{
Generic3<Integer> generic = new Generic3<Integer>() ;
generic.setFoo(new Integer(4)) ;
GenericTest<String> test = new GenericTest<String>();
}
}
class Generic3<K>
{
private K foo ;
public K getFoo()
{
return foo;
}
public void setFoo(K foo)
{
this.foo = foo;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
改为 public class GenericTest<K>
V512 上面有这个教程,讲得很详细。
应该给GenericTest类中的K指定具体类型。
建议不要在Java泛型上花费太多精力,其作用实在有限。
应该是这样吧
public class GenericTest<T,K>