Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Parameterized Typing
Apex, in general, is a statically-typed programming language, which means users must
specify the data type for a variable before that variable can be used.
This is legal in Apex:
1Integer x = 1;This is not legal, if x has not been defined
earlier:
1x = 1;Lists, maps and sets are parameterized in Apex: they take any data type Apex
supports for them as an argument. That data type must be replaced with an actual data
type upon construction of the list, map or set. For
example:
1List<String> myList = new List<String>();Subtyping with Parameterized Lists
In Apex, if type T is a subtype of U, then List<T> would be a subtype of List<U>. For example, the following is
legal:
1List<String> slst = new List<String> {'alpha', 'beta'};
2List<Object> olst = slst;