While researching the possibility of using generics in apex I can across a blog with this:
"Generics are partially supported in Apex, you must be using them with Collections and Batch Apex."
However, I couldn't really find any more information on that. Can generics be used in apex? What are the limitations?
By generic I mean in a "generic programming" sense where types are not defined in code but determined at run time. For example, I would like to be able to write a List iterator in apex but not have to define the object type. Something like:
global class ListIterator implements Iterator<T>{
global boolean hasNext(){
...
}
global T next(){
...
}
}
Where T would be defined at runtime - it could be Account, or Opportunity, or CustomObject1 or CustomClassX. Not only would it work with these data types but when I call hasNext() it would return an instance of that class (as opposed to returning a generic Object or sObject that I would then have to cast).