Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 194081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:33:53+00:00 2026-05-11T16:33:53+00:00

I want to define an interface MyList which is a list of interface MyThing.

  • 0

I want to define an interface MyList which is a list of interface MyThing. Part of the semantics of MyList is that its operations don’t have any meaning on objects which do not implement the MyThing interface.

Is this the right declaration?

interface MyList<E extends MyThing> extends List<E> { ... }

edit: (part 2) Now I have another interface that returns a MyList as one of its methods.

// I'm defining this interface
// it looks like it needs a wildcard or template parameter
interface MyPlace {
    MyList getThings();
}

// A sample implementation of this interface
class SpecificPlace<E extends MyThing> implements MyPlace {
    MyList<E> getThings();
}

// maybe someone else wants to do the following
// it's a class that is specific to a MyNeatThing which is
// a subclass of MyThing
class SuperNeatoPlace<E extends MyNeatThing> implements MyPlace {
    MyList<E> getThings();
    // problem?
    // this E makes the getThings() signature different, doesn't it?
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:33:53+00:00Added an answer on May 11, 2026 at 4:33 pm

    Yes, at least that is how EnumSet does it.

    public abstract class EnumSet<E extends Enum<E>>
    extends AbstractSet<E>


    Edit in answer to Part 2:

    I’m not sure why the return type of getThings() in the interface doesn’t complain about raw types. I suspect that because of type erasure, warnings in interfaces would be useless even if they were there (there’s no warning if you change the return type to List, either).

    For the second question, since MyNeatThing extends MyThing, E is within its bounds. That’s sort of the point of using the extends bound in the generic parameter, isn’t it?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why would I want to define a C++ interface that contains private methods? Even
I want to make an application with plugins that also can have plugins (which
I want to define an interface IFile that includes an array of key/value pairs
I'm trying do define an interface in which I want to plot some values
I want to define injection so that only if the injected interface has EJB
I want to make an interface in C# that defines a method that always
I want to define the data.store that store companyList, because I want to reuse
I want to define a class that is able to populate itself reading from
I want to define functions that can be used in the fixedpoint rule. For
I have several classes that implement the same interface. interface IBidManager<E> where E :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.