Table of contentsGenerics in Java 5 Lots of New Language Features in Java 5… The new features work together… …varargs… …autoboxing… … …generics… …foreach How did that work? How does it work now? Common operations are now typesafe Customise Collection Classes Customise Collection Classes (continued) Reveal implicit type requirements of interfaces Add control over argument validation Add control over argument validation (continued) But Java has always been able to do that! Arrays are covariant Covariance requires RTTI Generics can’t have RTTI Erasure Erasure (continued) So generic classes can’t be covariant How will we do without covariance? How will we do without covariance? (continued) Wildcards Wildcards (continued) Using a wildcard type restricts access Using a wildcard type restricts access (continued) Bounded wildcards can work together Bounds work with type variables too Erasure produces some surprises Erasure produces some surprises (continued) Conclusions References |
Author: Maurice Naftalin E-mail: maurice-(at)-morninglight.co.uk |