Can generating an implementation of a public interface create public methods?
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)
-
-
repo owner - changed status to resolved
I actually just delivered this in 2.1.4.9. Sorry it took so long! It had slipped off my radar...
-
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.
-
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. -
repo owner I just committed a fix for this particular situation for inclusion in the next build.
-
repo owner Additional fix delivered in 2.1.5.4.
- Log in to comment
Yes indeed, a implementation of a method in a private (inner) class should be at least always public