Home > Back-end >  The idea of a small problem
The idea of a small problem

Time:09-17

Small white one, excuse me how from the image below int index into the Object O type switch, automatic identification has been index, I press the up and down key is useless,

CodePudding user response:

It's not a question of IDEA, this is because the ArrayList has two overloaded the remove method:

 public Boolean remove (Object o); 
Public E remove (int index);


Compiler is according to the signature of the method to determine which overloads, call when you use the remove (100), the compiler to find matching method is to remove (int index), rather than remove (Object o), if you want to call the latter, can be changed to:

 list. Remove (Integer. The valueOf (100)); 


After packing number is an Object, the compiler to find matching method is to remove (Object o)


CodePudding user response:

reference 1st floor winner245 response:
it's not a question of IDEA, this is because the ArrayList has two overloaded the remove method:

 public Boolean remove (Object o); 
Public E remove (int index);


Compiler is according to the signature of the method to determine which overloads, call when you use the remove (100), the compiler to find matching method is to remove (int index), rather than remove (Object o), if you want to call the latter, can be changed to:

 list. Remove (Integer. The valueOf (100)); 


After packing number is an Object, the compiler to find matching method is to remove (Object o)

Positive solution

CodePudding user response:

reference 1st floor winner245 response:
it's not a question of IDEA, this is because the ArrayList has two overloaded the remove method:

 public Boolean remove (Object o); 
Public E remove (int index);


Compiler is according to the signature of the method to determine which overloads, call when you use the remove (100), the compiler to find matching method is to remove (int index), rather than remove (Object o), if you want to call the latter, can be changed to:

 list. Remove (Integer. The valueOf (100)); 


After packing number is an Object, the compiler to find matching method is to remove (Object o)

Good thanks

CodePudding user response:

CodePudding user response:

And you create ArrayList Has good generics

CodePudding user response:

This is the function has been defined, the parameters to the object directly to you try
  • Related