function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
alexf99alexf99 

No common root class exposed for Apex classes?

Hi,

 

I'm fairly new to Apex, so hopefully I've just missed something. It seems to me that there is no common superclass of all Apex classes. We have Object, which is the superclass of all sObjects. But nothing for Apex classes themselves.

 

As a result it's impossible for example to have any generic methods for working with Lists of Apex objects, only sObjects.

 

E.g. what would work instead of the ??? below:

 

public class ListUtil {
  
  public static Boolean contains(List<???> theList, ??? element) {

 

for (??? obj : theList) if (obj == element) return true;

return false; 

 

  }
 

}

 

So you might want to be able to...

 

List<ApexPages.Message> messages = ... 

ApexPages.Message aMessage =  ...

ListUtil.contains(messages, aMessage);

 

 or

 

List<MyApexClass> aList = ... 

MyApexClass element =  ...

ListUtil.contains(aList, element);

 

Not possible? This would be useful, particularly for unit tests!

 

Alex