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

  • SEARCH
  • Home
  • 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 8963769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:25:53+00:00 2026-06-15T16:25:53+00:00

I have an interface like this: public interface SuperInterface { public interface SubInterface {

  • 0

I have an interface like this:

public interface SuperInterface {
    public interface SubInterface {
        public void get();
    }
    //**More interfaces*/

}

this method in my Toolkit, which retrieves all objects which are instance of a certain class:

public static <T> ArrayList<T> getSome(ArrayList<Object> objects, Class<T> clazz) {
    ArrayList<T> result = new ArrayList<T>();
    for (Object o : objects) 
        if (clazz.isInstance(o)) 
            result.add(clazz.cast(o));
    return result;
}

MyClass is not really interesting, its an empty class implementing from SuperInterface.SubInterface

And this piece in the main:

ArrayList<Object> mObjects = new ArrayList<Object>() {
    {
        add(new MyClass()); //SuperInterface.SubInterface
        add(Integer.valueOf(5));
        add(new String("Hello"));
        add(new Object());
    }
};
ArrayList<SuperInterface> mSuperInterfaces = Toolkit.getSome(mObjects, SuperInterface.class); //returns a zero-sized list.
ArrayList<SuperInterface.SubInterface> mSubInterfaces = Toolkit.getSome(mObjects, SuperInterface.SubInterface.class); //returns a one-sized list

The first method call does not work as I hoped, the second does. Is it possible so that the first one works without explicitly putting the subinterfaces in a different file and implementing the superclass? Because apparently the subinterfaces aren’t really subinterfaces, so I tried to make the Interface class like this:

public class ClassWithInterfaces {
  public interface Super { }
  public interface Sub implements Super { /**...*/ }
}

But apparently you can’t use implements in an inner interface.

My question is: Why is that, and is there a way to accomplish what I want to achieve (inner interfaces in one file)? I don’t necessarily need it, I merely want to know why it’s not possible to implement in inner interfaces (yet it’s possible to extend inner classes).

  • 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-06-15T16:25:54+00:00Added an answer on June 15, 2026 at 4:25 pm

    But apparently you can’t use implements in an inner interface.

    You’re looking for extends rather than implements:

    public class ClassWithInterfaces {
      public interface Super { }
      public interface Sub extends Super { /**...*/ }
    }
    

    This compiles for me, and I can certainly implement both interfaces.

    Since there appears to be some confusion around extending vs implementing, perhaps the following will help clear things up:

    • An interface extends another interface.
    • A class implements an interface.
    • A class extends another class.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interface definded like this: public interface IDatabase{ void Get<TTypeToFetch> ();} and
I have a proxied method in a MongoRepository extender class like this: public interface
I have crated an interface like this public interface NetworkInterface { public void onReceive();
Let's say I have an interface, like this: public interface ILoggable { void Log(Func<string>
I have an interface like this: public interface IFoo { int A {get;} int
I have an interface like this: public interface BatchSynchronisedPool<R extends Runnable> { void execute(R
I have an interface defining a method like this : public List<IA> myMethod(); with
I have an interface like this: public interface DataObject { ... public void copyFrom(DataObject
I have an interface like this: public interface IUser{ //some properties here T ToDerived(User
I have an interface and a class implementing the interface like this: public interface

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.