Closed kennethkks closed 3 years ago
Yes it is related. A loose rule of thumb would be a producer-like object that produces objects of type T can be of type parameter <? extends T>, while a consumer-like object that consumes objects of type T can be of type parameter <? super T>.
In this case, we can invoke the covariant rule, which says if A2 <: T then Optional
We can also have contravariant rule, which implied that if S <: A2, then Stream
Hope it answers!
Ok thanks for the explanation!
Description
Not sure how about the answers that i got after running in jshell. Is this related to Covariance and Contravariance?
Screenshots (if any):