Community
Participate
Working Groups
Using JDK: java version "1.5.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64) Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing) ---- // A generic data factory interface DataFactory<T> { public T create(Object[] fields); } // A data class class Foo {} // A non-generic data factory that makes Foo class PlaydohFooFactory implements DataFactory<Foo> { // Eclipse complains at the line below, because of the revised // return type public Foo create(Object[] fields) { // ... do stuff return new Foo(); } } // This bug is important to me because I'm trying to take a class // like this: class DataReader { <T> List<T> read(String filename, DataFactory<T> factory) { List<T> results = new ArrayList<T>(); // Open the file, then for each record... Object[] fields = { "first field", "second field", "third field" }; // for example results.add(factory.create(fields)); // ... return results; } } // .. and use it to do this class UsefulStuff{ public void beUseful() { // DataReader reads a file, and passes the fields for each // entry to the DataFactory so it can create an object. DataReader reader = new DataReader(); // Compile a list of objects, using PlaydohFooFactory to parse the // fields and instantiate the object List<Foo> pileOfFoo = reader.read("filename.csv", new PlaydohFooFactory()); } } ---- Using the Sun command-line compiler, this code compiles with no warnings. In Eclipse 3.1 M4, I get a warning message for the method with the revised return type: ---- Type safety: The return type Foo of the method create(Object[]) of type PlaydohFooFactory needs unchecked conversion to conform to the return type T of inherited method .. but I already specified that Foo IS_A T in the "implements DataFactory<Foo>" part! ---- Expected behavior: Eclipse should not flag a warning for this code.
*** This bug has been marked as a duplicate of 81618 ***