Java Reference
In-Depth Information
΢΢ Exercise R17.10. Explain the type bounds of the following method of the
Collections class:
public static <T extends Comparable<? super
T>> void sort(List<T> a)
Why doesn't T extends Comparable or T extends
Comparable<T> suffice?
΢ Exercise R17.11. What happens when you pass an
ArrayList<String> to a method with parameter ArrayList? Try it
out and explain.
΢΢΢ Exercise R17.12. What happens when you pass an
ArrayList<String> to a method with parameter ArrayList , and
the method stores an object of type BankAccount into the array list?
Try it out and explain.
΢΢ Exercise R17.13. What is the result of the following test?
ArrayList<BankAccount> accounts = new
ArrayList<BankAccount>();
if (accounts instanceof ArrayList<String>) .
. .
Try it out and explain.
783
784
΢΢΢ Exercise R17.14. If a class implements the generic Iterable
interface, then you can use its objects in the Ȓfor eachȓ loopȌsee
Advanced Topic 15.1 . Describe the needed modifications to the
LinkedList<E> class of Section 17.2 .
Additional review exercises are available in WileyPLUS.
PROGRAMMING EXERCISES
΢ Exercise P17.1. Modify the generic Pair class so that both values have
the same type.
Search WWH ::




Custom Search