且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有泛型和迭代器的java编译器错误

更新时间:2023-09-24 16:26:34

Here,

public class MyList<Integer> extends ArrayList<Integer> {
                //  ^ here

you are declaring a type variable Integer which shadows the java.lang.Integer type.

Anywhere within the type body where you refer to Integer, you are referring to the type variable rather than the java.lang.Integer type.

The various numerical operators do not apply to random types (which is what your type variable is), they only work with primitive numeric types and their wrapper classes. Therefore you can't use them with operands of the type of your type variable.

相关阅读

推荐文章