简体   繁体   English

为什么我会收到未经检查的作业警告?

[英]Why do I get an unchecked assignment warning?

I have the following interface and class definitions... 我有以下接口和类定义...

abstract interface I{}

class Foo implements I{}

abstract class A<T extends I> {
    List<T> list;
}

class B extends A<Foo> {}

All the definitions work fine. 所有定义都可以正常工作。 I then want to do the following: 然后,我想执行以下操作:

A b = new B();
List<? extends I> iList = b.list;

The compiler will indeed give me an Unchecked Assignment warning... but why? 编译器确实会给我Unchecked Assignment警告...但是为什么呢? Won't all of A 's lists be of type <? extends I> A的所有列表都不会是<? extends I> <? extends I> ? <? extends I> b.list always has elements that extend I, so I am having trouble seeing why there would be an error b.list总是具有扩展I的元素,因此我很难理解为什么会出现错误

The variable A b is of a raw type. 变量A b是原始类型。 Perhaps you meant to use A<Foo> b instead. 也许您打算使用A<Foo> b代替。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM