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 6727949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:06:38+00:00 2026-05-26T10:06:38+00:00

I have this interface: public interface ISectionListItem { public int getLayoutId(); public void setProps(View

  • 0

I have this interface:

public interface ISectionListItem {
    public int getLayoutId();
    public void setProps(View view, int position);  
}

But i want all the classes who implements this interface be forces to have a static class inside them. I thought of:

 public interface ISectionListItem {
    public int getLayoutId();
    public void setProps(View view, int position);

    static class ViewHolder {};
}

But that dosn’t force the classes to “add unimplemented inner classes”. Anyway to accomplish this? Is it even possible?

Thanks 🙂

  • 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-26T10:06:40+00:00Added an answer on May 26, 2026 at 10:06 am

    This is not possible by the nature of interfaces. An interface defines the public behavior of objects; if a class implements an interface, that means that all instances of that class obey the contract defined by the interface. For this reason interfaces can’t contain static members. (There’s an exception to this rule, but at this point you shouldn’t care about that.)

    Be careful of your terminology: static member classes are not inner classes. Static member classes are like normal classes, except that they live in a different namespace. Static member classes are not members of the instances of the containing class, just as any static class member is not part of the “instance template”. An inner class is by definition not static.

    So, why can’t we declare a genuine (i.e. non-static) inner class in an interface? That’s because in an interface you can only define the behavior of objects, not how they are composed. The whole point (and beauty) of interfaces is that they separate the behavior (“what does it do”) from the implementation (“how is it done”). For that reason you can’t declare inner classes in an interface, just as you can’t declare fields in an interface.

    I don’t know what you’re trying to do, but you might want to try the following. Let’s call your original interface MyInterface.

    1. Define an extra interface SomeType
    2. Have your inner class implement SomeType
    3. Declare a method like public SomeType getInnerClassInstance() (a terrible method name) in MyInterface

    Note that MyInterface instances aren’t forced to actually return an instance of an inner class as a result of getInnerClassInstance(). This is a nice thing, because you’re not bound to a specific implementation.

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

Sidebar

Related Questions

So lets say I have this interface: public interface IBox { public void setSize(int
I have this interface: public interface IValidationCRUD { public ICRUDValidation IsValid(object obj); private void
I have a model that looks like this: public interface IEntity { int Id
I have this interface public interface MyInterface{ Collection<T> Find(T t); Collection<T> FindAll(); T FindById(int
Lets say we have this interface: public interface ILog { void Add(Message message); }
Let's supposed i have this interface: public interface MyInterface { void doStuff(); } With
Suppose I have this interface public interface IFoo { ///<summary> /// Foo method ///</summary>
Say I have this code - public interface ParentInterface1 { public List<? extends ChildInterface1>
I have this code (which is way simplified from the real code): public interface
This question was asked at interview. Say I have a contract. [ServiceContract] 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.