Error is coming in Arraylist 's list.add()

后端 未结 3 1920
星月不相逢
星月不相逢 2021-01-14 03:42

I am using Eclipse JUno ,I am having trouble with the .add() of the arraylist guys please help.here is my code

     import java.util.ArrayList;
public class          


        
3条回答
  •  天命终不由人
    2021-01-14 04:03

    I suppose that you're using java prior version 1.5. Autoboxing was introduced in java 1.5. And your code compiles fine on java 1.5+.

    Compile as source 1.4:

    javac -source 1.4 A.java
    
    
    A.java:7: error: no suitable method found for add(int)
        list.add(90);
            ^
        method ArrayList.add(int,Object) is not applicable
          (actual and formal argument lists differ in length)
        method ArrayList.add(Object) is not applicable
          (actual argument int cannot be converted to Object by method invocation conversion)
    A.java:8: error: no suitable method found for add(double)
        list.add(9.9);
            ^
        method ArrayList.add(int,Object) is not applicable
          (actual and formal argument lists differ in length)
        method ArrayList.add(Object) is not applicable
          (actual argument double cannot be converted to Object by method invocation conversion)
    A.java:10: error: no suitable method found for add(boolean)
        list.add(true);
            ^
        method ArrayList.add(int,Object) is not applicable
          (actual and formal argument lists differ in length)
        method ArrayList.add(Object) is not applicable
          (actual argument boolean cannot be converted to Object by method invocation conversion)
    3 errors
    

    With 1.5 (or later):

    javac -source 1.5 A.java
    
    warning: [options] bootstrap class path not set in conjunction with -source 1.5
    Note: A.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 warning
    

    I suggest you to update your java or box all primitives to objects manually, as @SoulDZIN suggested.

提交回复
热议问题