-1
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    The operator + is undefined for the argument type(s) java.lang.Integer,
    java.lang.Integer

    at TestClass.Print3.main(Print3.java:14)
public class Print3 {
    public static Integer wiggler(Integer x) {
        Integer y = x+10;
        x++;
        System.out.println(x);

        return y;
    }

    public static void main(String[] args) {
        Integer dataWrapper = new Integer(5);
        Integer value = wiggler(dataWrapper);
        System.out.println(dataWrapper+value);
    }
} 
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • public class Print3 { public static Integer wiggler(Integer x) { Integer y = x+10; x++; System.out.println(x); return y; } public static void main(String[] args) { Integer dataWrapper = new Integer(5); Integer value = wiggler(dataWrapper); System.out.println(dataWrapper+value); } } –  May 20 '15 at 08:29
  • 5
    please do not add your source as a comment, edit your question. – reto May 20 '15 at 08:30
  • Please edit your question to add source code, and a clear question. What are you expecting for ? – Kapcash May 20 '15 at 08:32
  • Your code works fine for me. – Eran May 20 '15 at 08:32
  • 1
    Do you understand the [difference between `int` and `Integer`](http://stackoverflow.com/questions/16836282/difference-between-int-and-integer)? – Jesper May 20 '15 at 08:41

2 Answers2

1

I haven't seen this compile error before, its very strange to me because normally Java compiler will unbox the Integer object into a int primitve type and use the addition.

I have compiled your file and look at the binary code:

  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: ACC_PUBLIC, ACC_STATIC
    Code:
      stack=3, locals=3, args_size=1
         0: new           #6                  // class java/lang/Integer
         3: dup
         4: iconst_5
         5: invokespecial #7                  // Method java/lang/Integer."<init>":(I)V
         8: astore_1
         9: aload_1
        10: invokestatic  #8                  // Method wiggler:(Ljava/lang/Integer;)Ljava/lang/Integer;
        13: astore_2
        14: getstatic     #4                  // Field java/lang/System.out:Ljava/io/PrintStream;
        17: aload_1
        18: invokevirtual #2                  // Method java/lang/Integer.intValue:()I
        21: aload_2
        22: invokevirtual #2                  // Method java/lang/Integer.intValue:()I
        25: iadd
        26: invokevirtual #9                  // Method java/io/PrintStream.println:(I)V
        29: return
      LineNumberTable:
        line 11: 0
        line 12: 9
        line 13: 14
        line 14: 29
}

I omitted the uninteresting binary code because the interessting part is in the main Method. What i want to show you is that the Java Compiler will automatically unbox the Wrapper class into an int primitive type with the call Method java/lang/Integer.intValue:()I in line 18 and 22 after that the addition will be executed.

So the other answers will no help neither.

I will suggest to use another Java Compiler respectively update your jdk and try to compiler it on another machine.

You can also test you code with ideone and as you see it works perfectly.

http://ideone.com/9tJYf1

Zelldon
  • 5,396
  • 3
  • 34
  • 46
0

Try using this code instead:

public class Print3 {
    public static Integer wiggler(Integer x) {
        Integer y = new Integer(x.intValue() + 10);
        x = new Integer(x.intValue() + 1);
        System.out.println(x);

        return y;
    }

    public static void main(String[] args) {
        Integer dataWrapper = new Integer(5);
        Integer value = wiggler(dataWrapper);
        int result = dataWrapper.intValue() + value.intValue();
        System.out.println(result);
    }
}

As @Eran mentioned, I would have expected your code to work without issues. Apparently your version of Java is choking on the addition of two Integers.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Thanks so much Tim, I am new here, please bear with me if it takes time for me to understand rules and explanations given/stated. –  May 21 '15 at 15:14