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?

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

1

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 {
    }
}
  • 3
    Your second example does not compile. – Keith C Aug 5 '16 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.