4

Can interface have inner classes or interfaces? Looks like it is not possible and the answer is no, however it is not mentioned anywhere in the documentation https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_interfaces.htm

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_access_modifiers.htm

Can anyone explain why it is not mentioned in documentation and why this is not possible in Salesforce Apex?

2 Answers 2

1

Interfaces in Apex is same like Interfaces in Java. I just googled and found this question in stackoverflow.

The excerpt which i like to point is

interface is meant to declare just to provide interface not for implementation

0

Yes, you can create both an inner class or an inner interface inside a apex interface just like java. the following compiles fine:

public interface A {
    class B {
    }
}
public interface A {
    interface B {
    }
}
1
  • 5
    Your second example does not compile.
    – Keith C
    Aug 5, 2016 at 11:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .