Skip to content

Why use super in crazy generics module #158

Answered by aquariusmaster
homosapi3n asked this question in Q&A
Discussion options

You must be logged in to vote

Suppose we have next classes:

class A implements Comparable<A>
class B extends A

With MaxHolder<T extends Comparable< T >> you will not be able to put B in MaxHolder, because B does not implement Comparable<B>, it implements Comparable<A>.
By using MaxHolder<T extends Comparable<? super T>> you can do that because MaxHolder will accept Comparable<A>.
May be useful: https://stackoverflow.com/a/25783345

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@homosapi3n
Comment options

Answer selected by tboychuk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants