Java Generics - 6. Typed Classes as method parameters
This is part 6 of the 9 part series on Java Generics Prev Topic Wildcards Topics 1. Introduction 2. Bounding 3. Multiple bounding 4. Generic Methods 5. Wildcards 6. Typed Classes as method parameters 7. Upper and Lower Bounds 8. Target Types 9. Type Erasure Next Topic Upper and Lower Bounds Java Generics - Typed Classes as Method Parameters We saw in the previous section, that List which is a typed interface can be used either with the wildcard (?) or with a defined type E , ‘ E extends Number’ in this case. Can we use it with a Fruit that is exportable? Why not, the rules are same. Here is a method which gives the maximum price for all Exportable fruits in a list. public static <E extends Fruit & Exportable> double maxPrice1(List<Bean<E>> beans ){ double max = 0; fo...
Comments
Post a Comment