Suitably extended, the earlier approach probably produces faster machine code.

The check can be avoided if the compiler can figure out what is going on at compile time, or if "T" has no subtypes. Both primitive types and final classes satisfy this latter property, but Sun's current Java interpreter only removes the type check for the primitive type case.

Andrew C. Myers, Joseph A. Bank, Barbara Liskov
Copyright © 1996 Association for Computing Machinery