Bug 83269 - Nongeneric subclass of generic base class - warning when revising return type of typed methods
Summary: Nongeneric subclass of generic base class - warning when revising return type...
Status: RESOLVED DUPLICATE of bug 81618
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-19 21:31 EST by Matthew Hall CLA
Modified: 2005-01-19 22:47 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Hall CLA 2005-01-19 21:31:45 EST
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.
Comment 1 Matthew Hall CLA 2005-01-19 22:47:22 EST

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