Bug 81890

Summary: [5.0] 3.1M4 spurious type-safety compiler warning
Product: [Eclipse Project] JDT Reporter: mike andrews <mikea>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3    
Version: 3.1   
Target Milestone: 3.1 M5   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description mike andrews CLA 2004-12-23 22:43:53 EST
given the following two classes:

package test.a;

public class TestB {

}

package test.a;

import java.util.concurrent.Callable;
import java.util.concurrent.CompletionService;
import java.util.concurrent.Future;

public class TestA {

    private CompletionService<TestB> cs;

    public Future<TestB> submitTask(String command) {
        return cs.submit(new Callable<TestB>() {
            public TestB call() throws Exception {  // LINE IN QUESTION
                return new TestB();
            }
        });
    }
}

i get a compiler warning: "Type safety: The return type TestB of the method
call() of type new Callable<TestB>(){} needs unchecked conversion to conform to
the return type V of inherited method" in TestA.java

this doesn't seem correct, since i can use a non-anonymous class instead (for
the line in question), with no compiler warning.
Comment 1 mike andrews CLA 2004-12-23 22:57:42 EST
hmmmm.... still get the error without anonymous class now... but the following
standalone class completely demonstrates the problem: indicated line generates
compiler warning "Type safety: The return type String of the method call() of
type Test needs unchecked conversion to conform to the return type V of
inherited method":


package test.a;

import java.util.concurrent.Callable;

class Test implements Callable<String> {

    public String call() throws Exception { // THIS LINE GENERATES WARNING
        return new String("");
    }

}
Comment 2 Frederic Fusier CLA 2004-12-24 03:36:05 EST

*** This bug has been marked as a duplicate of 79687 ***