Why does Apex Code let me save a parameterized interface?

For some reason, I thought I’d see if interfaces support parameterization, as a matter of trying to optimize some code. Amazingly, the following code saved once:

public interface ITriggerHandler<T> {
    void handle();

And after trying to modify it, it would refuse to compile, stating that paramterization isn’t supported. I also tried using:

public class AccountTriggerHandler implements ITriggerHandler<Account> {
    public void handle() { /* */ }

This refused to compile, stating that the dependent class was invalid and required re-compilation (parameterization isn’t supported).

Perhaps I’ve found a glitch in the compiler?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

One of the reason what i could found is Apex is unable to type cast between sObject to Object or vice-versa.

So it results, unable to support generics because some how it can not find whether passed argument is sObject or Object. They both are isolated. Perhaps apex is unable to handle this scenario.

In addition, Interface taken as example is saved only once. If its parameter is edited to <Object> or some other it won’t save and even if we change it again to previous state <T> it will refuse to save.

showing error: Itriggerhandler: line 1, column 18: type parameters not supported at line 1 column 47


In summary we can say it is a some bug that it allow to save generic parameterized class to save but unable to re-save. Not supporting the generic type is hidden in between the isolation between sObject and Object. The way of Apex handle the top-level objects.

Hope it may clear some points.

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x