Results 1 to 2 of 2
  1. #1
    lulseged is offline Member
    Join Date
    Jun 2010
    Posts
    1
    Rep Power
    0

    Smile Define a generic property

    Hi

    I am trying to define a generic type in a set. But I don't know if it is possible.

    Protected Set<E extends EntityType> entity = new HashSet<E>(0);

    I have tried to use in the classes declaration but I have a lot of Set properties and the class definition will be very long which must be in every class where this property is declared.

    public class ListType<E extends EntityType>
    {
    Set<E> entity = new HashSet<E>(0); // this works
    }

    Is it possible to declare like:
    public class ListType
    {
    Set<E extends EntityType> entity = new HashSet<E>(0);
    // this doesn't work
    }

    Lulseged

  2. #2
    HerrK. is offline Member
    Join Date
    Jun 2010
    Location
    Berlin
    Posts
    22
    Rep Power
    0

    Default

    Is it possible to declare like:
    public class ListType
    {
    Set<E extends EntityType> entity = new HashSet<E>(0);
    // this doesn't work
    }
    Well, it is possible to use something like this:

    Java Code:
    public class ListType {
      Set<? extends EntityType> entity = new HashSet<EntityType>(0);
    }
    But I am not sure why you need something like that. Maybe if you could go more into detail (including some example) why the first choice isn't applicable to your problem?

    Best regards,
    Herr K.

Similar Threads

  1. Define class and constructors
    By HaDesT in forum New To Java
    Replies: 2
    Last Post: 03-04-2010, 05:02 PM
  2. define a variable
    By jperson in forum New To Java
    Replies: 2
    Last Post: 01-29-2010, 02:33 AM
  3. Define this error.
    By jaicea in forum New To Java
    Replies: 3
    Last Post: 12-02-2009, 01:07 AM
  4. How to define boolean in the fields ?
    By racewithferrari in forum New To Java
    Replies: 3
    Last Post: 11-26-2009, 06:01 PM
  5. Replies: 0
    Last Post: 06-25-2009, 05:28 AM

Posting Permissions

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