Are Apex interfaces and abstract classes case-sensitive?

My understanding from the docs is that apex class and method names are case-insensitive.

I’ve run across an edge-case with interfaces and abstract classes which appears to be undocumented behavior where it is case-sensitive. The following 3 stub classes reproduce the issue which I believe is a compiler bug.

Base Interface

public interface overrideInterface {
    void camelCase();
}

Abstract Class

public abstract class SL_override implements overrideInterface{
    public virtual void camelCase() {
        system.debug('should never run.');
    }
}

Class to Run

public class SL_newOverride extends SL_Override {
    //capital A
    public override void camelCAse(){
        system.debug('will never run.');
    }
}

Anonymous Apex

SL_newOverride foo = new SL_newOverride();
foo.camelCase();

If you run this anonymous apex it appears to never enter the methods and errors out:

Error on line -1, column -1: System.LimitException: Maximum stack depth reached: 1001
External entry point
External entry point
External entry point
External entry point
External entry point
External entry point
External entry point
External entry point
...

Answer

This is an unique case. I tried your code and got the same stack depth error. But I play around with the method name and what I observed that not all the combinations of Upper-case and Lower-case letters in the method name are behaving in the same way. For example, I changed the Interface class method name as follows

    public interface overrideInterface {
    void camelcaSE();
    void METHOD2();
}

Then I change the Abstract Class method name as follows

public abstract class SL_override implements overrideInterface{

     public virtual void camelCase() {
        system.debug('should never run.');
    }
      public virtual void Method2() {
        system.debug('Abstract class Method2() display- Interface method name - METHOD2()');
    }
}

Then I changed the method name in the child class as follows

public class SL_newOverride extends SL_Override {

    public override void camelcASE(){
        super.camelcase();
        system.debug('will never run.');
    }

    public override void metHod2(){
        super.method2();
        system.debug('method2 display.');
    }
}

Then I invoke and execute the child class through anonymous apex as follows

SL_newOverride foo = new SL_newOverride();
foo.camelCasE();

And it works fine. The only situation the case-sensitivity is becoming the issue is camelCAse(). Otherwise, I don’t think the Apex naming convention is case-sensitive. The proof is with the second method name Method2 which I declared in the interface class and overridden in the abstract and child classes.

SL_newOverride foo = new SL_newOverride();
foo.camelCasE();
foo.Method2();

So we can’t conclude that Salesforce Apex class methods are case sensitive.

Attribution
Source : Link , Question Author : Greg Grinberg , Answer Author : Prolay Chaudhury

Leave a Comment