Section 20.4 Additional Compile-Time Translation Issues: Methods That Use a Type Parameter as the Return Type

• When a generic method is compiled, the compiler performs erasure (p. 848) to remove the type-parameter section and replace the type parameters with actual types. By default each type parameter is replaced with its upper bound (p. 848), which is Object unless specified otherwise.

• When erasure is performed on a method that returns a type variable (p. 848), explicit casts are inserted in front of each method call to ensure that the returned value has the type expected by the caller.

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.