Can generating an implementation of a public interface create public methods?

Issue #1464 resolved
Aidan Harding created an issue

If I write a public interface e.g.

public interface Function {
    Object call(Object o);
}

And then add a private inner class to implement it:

public class GenerateImplementation {

    private class MyFunction implements Function {
    }

}

Then, use the IDE to “Implement Methods”, the visibility of the new method matches the enclosing class:

public class GenerateImplementation {

    private class MyFunction implements Function {
        private Object call(Object o) {
            return null;
        }
    }
}

This is not actually valid Apex, as the methods implementation a public interface must themselves be public.

It’s easy enough to fix, but it’s something I regularly forget to do until I push/deploy and get an error back from the server. It would be really nice to have it generate as public.

Comments (6)

  1. Theodoor van Donge

    Yes indeed, a implementation of a method in a private (inner) class should be at least always public

  2. Aidan Harding reporter

    Hi Scott,

    Sorry, but this is still causing trouble. I think that the new method is being generated to match the access of the interface. That’s not quite right because if the interface is global but the class is not, the generated code is still not legal.

    For example, I end up with:

    private class NewVenueOrOnlineValue implements nebc.Function {
        global Object call(Object o) {
            return null;
        }
    }
    

    Which is not legal. I’d want it to generate the call() function as public in this case.

  3. Scott Wells repo owner

    Aha. That's certainly a strange combination...a private top-level type containing an externally-accessible implementation of an interface method. I'll make sure that it's handled properly, though.

  4. Scott Wells repo owner

    I just committed a fix for this particular situation for inclusion in the next build.

  5. Log in to comment