Community
Participate
Working Groups
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.
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(""); } }
*** This bug has been marked as a duplicate of 79687 ***