Closed runeflobakk closed 10 years ago
Not possible... http://stackoverflow.com/questions/4902723/why-cant-a-java-type-parameter-have-a-lower-bound Basically due to Java being oriented towards mutability, and has use-site variance. If only Java generics had declaration-site variance... http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)#Generic_types
This also prevents #37 from being implemented.
It is sometimes useful to upcast an Optional to a less specific type
Say if your method is declared to return an
Optional<A>
, and your method prepares a valuev
of typeB extends A
. The statementreturn optional(v)
will not compile, since the type is inferred to beOptional<B>
Candidate method names:
.as(Class<N super V>): Optional<N>
.upcastTo(Class<N super V>): Optional<N>