更新时间: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.