1. A non-transitory, computer-readable storage medium storing program instructions that when executed on a computing device cause the computing device to perform: generating, by a compiler, a class file based on a class declaration, wherein said generating comprises: applying a type erasure operation to a stream of instructions for the class declaration, wherein the stream of instructions is for execution by a virtualized execution environment, and wherein the class declaration includes one or more type variables; wherein applying the type erasure operation comprises: encoding a program element of the class declaration with metadata to create an encoded form of the program element to provide type specialization, the metadata specifying specialization information regarding the program element indicating which of the type variables have been erased; including the encoded form of the program element in the class file, wherein the encoded form of the program element, when specialized for a particular type by the virtualized execution environment, is transformed based on the metadata to generate a specialized version of the program element according to a particular type parameterization for the particular type; and wherein the encoded form of the program element is also executable with no transformation by the virtualized execution environment.