Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.



Tags
#bloch-effective-java-2ed #java #java-generics
Question
Why would List<ScheduledFuture<?>> be rejected by a method:
public static <T extends Comparable<T>> T max(List<T> list)
but accepted (as intended) by this:
public static <T extends Comparable<? super T>> T max(List<? extends T> list)
?
Answer
java.util.concurrent.ScheduledFuture does not implement Comparable<ScheduledFuture>. Instead, it is a subinterface of Delayed, which extends Comparable<Delayed>. In other words, a ScheduledFuture instance isn’t merely comparable to other ScheduledFuture instances; it’s comparable to any Delayed instance, so we have to say Comparable<? super T>. Delayed is super of ScheduledFuture. It seems that the second part, List<? extends T> as a producer does not make any difference.

basically:
ScheduledFuture extends Comparable<Delayed>
where Delayed is super of ScheduledFuture

Tags
#bloch-effective-java-2ed #java #java-generics
Question
Why would List<ScheduledFuture<?>> be rejected by a method:
public static <T extends Comparable<T>> T max(List<T> list)
but accepted (as intended) by this:
public static <T extends Comparable<? super T>> T max(List<? extends T> list)
?
Answer
?

Tags
#bloch-effective-java-2ed #java #java-generics
Question
Why would List<ScheduledFuture<?>> be rejected by a method:
public static <T extends Comparable<T>> T max(List<T> list)
but accepted (as intended) by this:
public static <T extends Comparable<? super T>> T max(List<? extends T> list)
?
Answer
java.util.concurrent.ScheduledFuture does not implement Comparable<ScheduledFuture>. Instead, it is a subinterface of Delayed, which extends Comparable<Delayed>. In other words, a ScheduledFuture instance isn’t merely comparable to other ScheduledFuture instances; it’s comparable to any Delayed instance, so we have to say Comparable<? super T>. Delayed is super of ScheduledFuture. It seems that the second part, List<? extends T> as a producer does not make any difference.

basically:
ScheduledFuture extends Comparable<Delayed>
where Delayed is super of ScheduledFuture
If you want to change selection, open document below and click on "Move attachment"

pdf

owner: piotr.wasik - (no access) - Effective Java (Joshua Bloch), 2ed, p138

Summary

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Details

No repetitions


Discussion

Do you want to join discussion? Click here to log in or create user.