Skip to main content

First of all thank you for opening up this group and enabling the community to have a voice in this. I know it's a language feature many have long wanted!

 

I would really like to see type constraints when this is implemented. We have methods that accept either sObjects or collections of sObjects when we don't really mean any sObject. We really mean two or three specific sObject types. Or we might have methods that currently accept an instance of a class that implements an interface. But we might actually want to know what the class is (for example to return the same type instead of the interface).

 

I would imagine this might look something like

 

// Method that takes a list of sObjects that are all either obj1__c or obj2__c

public void mySObjectMethod(List<sObject:obj1__c|obj2__c> objects) {

}

// Method that takes a single object parameter that is of a class that implements interface MyInterface and returns an object of the same class

public T myObjectMethod(<T:MyInterface> arg) {

}

Finally we might want to apply this at a class level (in fact this may be the primary use case

// Parameterised class with a constraint that the type implements MyInterface

public with sharing MyClass<T:MyInterface> {

public T myMethod(T arg) {

}

}

4 comments
0/9000