How can I avoid specifying an outer class when using its nested class outside the outer?

For example, I have the following:

public with sharing class ClassA {
    public class NestedInA {


public with sharing class ClassB {
    public void methodWhicUsesNestedInA() {
        ClassA.NestedInA nestedInA = new ClassA.NestedInA();

I do not want to always write ClassA.NestedInA when I am using the NestedInA class inside ClassB. I would like to be able to write NestedInA instead. Is it possible? If so, then how?

Thank you.


You can't, unfortunately. Apex does not have an "import" function that you might expect from another C-family language, Python, etc. ClassA.NextedInA is going to be called exactly that everywhere except inside the scope of ClassA.

Your only option is to promote the inner class to its own outer class.

| improve this answer | |

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.