3

The below piece of code doesn't compile in Eclipse Luna with jdk 1.8.0_05. Eclipse compiler says : Type mismatch: cannot convert from Integer to long

It though compiles in Luna with jdk 1.7 and also compiles using jdk 1.8 when invoked from command line. Can anyone help me identify what could be wrong? Eclipse JDK?

The code works in : http://www.tryjava8.com/

public class TestJava8Issue {

    public static final int CORE_POOL_SIZE = Math.max(Runtime.getRuntime().availableProcessors() / 2, 2);
    public static final int KEEP_ALIVE_TIME = 60; // seconds

    TestJava8Issue(final int size, final long ttl){
        System.out.println("size: " + size + " " + " ttl: " + ttl);
    }

    public static void main(String[] args) {
        new TestJava8Issue(CORE_POOL_SIZE, get(KEEP_ALIVE_TIME));
    }

    public static <T> T get(T value) {
        return value;
    }
}

Eclipse Java Development Tools
Version: 3.10.0.v20140501-0200
Build id: I20140501-0200

java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

3
  • 2
    +1, Most likely an interesting case of target type inference running mad (i.e. a bug in the Eclipse compiler). Workarounds like get((long)KEEP_ALIVE_TIME) are possible, but one could consider filing this as a bug for the eclipse developer team. Commented Sep 21, 2014 at 12:47
  • 4
    bugs.eclipse.org/bugs/show_bug.cgi?id=440019 Commented Sep 22, 2014 at 0:22
  • 1
    stackoverflow.com/questions/27105299/… Commented Nov 24, 2014 at 14:35

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.