Results 1 to 2 of 2
  1. #1
    Arrowx7 is offline Member
    Join Date
    Aug 2008
    Rep Power

    Default Question about java generics

    Hello, here is the code that's throwing the compile error:

    Java Code:
    List<Document<TextType>> doclist = ......
    DocumentRegistry registry = new DocumentRegistry(doclist);

    Java Code:
    public DocumentRegistry(List<Document<?>> documents) {

    Java Code:
     cannot find symbol
    symbol  : constructor DocumentRegistry(java.util.List<org.myproj.Document<org.myproj.doctypes.TextType>>)
    if I change the constructor to
    public DocumentRegistry(List<Document<TextType>> documents)
    it works, but I want to pass in any document object. I thought the wildcard ? would include TextType;
    FYI, Document class is a wrapper class.
    and the DocumentRegistry extends HashMap for some reason if I remove "extends HashMap" it works! Why is that??

    Any help would be appreciated thanks!
    Last edited by Arrowx7; 08-12-2008 at 11:02 PM.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Rep Power


    Java Code:
    public DocumentRegistry(List<Document<?>> documents)
    This suggests that I could pass anything, eg, Point, to your Document and it would be okay.
    How about if you specified an extension of TextType or a superclass of TextType?
    Java Code:
    public DocumentRegistry(List<Document<? extends TextType>> documents)
    // or
    public DocumentRegistry(List<Document<? extends SuperClassOfTextType>> documents)

Similar Threads

  1. Generics
    By sireesha in forum New To Java
    Replies: 2
    Last Post: 01-11-2008, 12:08 AM
  2. Java confused over Generics?
    By Bibendum in forum New To Java
    Replies: 3
    Last Post: 12-26-2007, 07:23 AM
  3. Java Generics (an introduction)
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 11-27-2007, 07:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts