PDF4PRO ⚡AMP

Modern search engine that looking for books and documents around the web

Example: bankruptcy

More than you ever wanted to know about Java Generics

more than you ever wanted to know about Java Generics Jeff Meister CMSC 420 Summer 2007 Generics : A YOUNG LADY S ILLUSTRATED PRIMER IN FOUR SLIDES The obligatory review of the boring stuff, Java : Life Before Generics Java code used to look like this: List listOfFruits = new ArrayList(); (new Fruit( Apple )); Fruit apple = (Fruit) (0); (new Vegetable( Carrot )); // Whoops! Fruit orange = (Fruit) (0); // Run time error Problem: Compiler doesn t know listOfFruits should only contain fruits A Silly SoluMon We could make our own fruit only list class: class FruitList { void add(Fruit element) { .. } Fruit remove(int index) { .. } .. } But what about when we want a vegetable only list later? Copy paste? Lots of bloated, unmaintainable code? Java : Now We re Talking Now, Java code looks like this: List<Fruit> listOfFruits = new ArrayList<Fruit>(); (new Fruit( Apple )); Fruit apple = (0); (new Vegetable( Carrot )); // Compile time error Hooray!

More than you ever wanted to know about ... than you were without using generics at all. At least you know the code on your ...

Tags:

  More, Than, Know, You know, More than you, Than you

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Spam in document Broken preview Other abuse

Transcription of More than you ever wanted to know about Java Generics

Related search queries