In Apex, all variables and expressions have a data type that is one
of the following:
- A primitive, such as an Integer, Double, Long, Date, Datetime,
String, ID, or Boolean (see Primitive Data Types)
- An sObject, either as a generic sObject or as a specific sObject,
such as an Account, Contact, or MyCustomObject__c (see sObject Types in Chapter 4.)
- A collection, including:
- A list (or array) of primitives, sObjects, user defined objects,
objects created from Apex classes, or collections (see Lists)
- A set of primitives (see Sets)
- A map from a primitive to a primitive, sObject, or collection
(see Maps)
- A typed list of values, also known as an enum (see Enums)
- Objects created from user-defined Apex classes (see Classes, Objects, and Interfaces)
- Objects created from system supplied Apex classes
- Null (for the null constant,
which can be assigned to any variable)
Methods can return values of any of the listed types, or return
no value and be of type Void.
Type checking is strictly enforced at compile time. For example,
the parser generates an error if an object field of type Integer is
assigned a value of type String. However, all compile-time exceptions
are returned as specific fault codes, with the line number and column
of the error. For more information, see Debugging Apex.