A
- the covariant typeB
- the contravariant typepublic final class Upcast<A extends B,B> extends Object implements Fn1<A,B>
B
to a value of type A
that B
extends. This is
principally useful when dealing with parametric types that are invariant in their parameters and a cast is
necessary for compatibility purposes.
Example:
Iterable<String> have = new ArrayList<>();
Iterable<CharSequence> want = map(upcast(), have); // necessary due to invariance in parameter
Note that this is universally safe.
Modifier and Type | Method and Description |
---|---|
B |
checkedApply(A a)
Invoke this function with the given argument, potentially throwing any
Throwable . |
static <A extends B,B> |
upcast() |
static <A extends B,B> |
upcast(A a) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
andThen, apply, carry, cartesian, censor, choose, cocartesian, compose, contraMap, diMap, diMapL, diMapR, discardL, discardR, flatMap, fmap, fn1, fromFunction, lazyZip, listens, local, pure, pureFn1, thunk, toFunction, trampolineM, widen, zip, zip
public B checkedApply(A a)
Fn1
Throwable
.checkedApply
in interface Fn1<A extends B,B>
a
- the argumentpublic static <A extends B,B> Upcast<A,B> upcast()
public static <A extends B,B> B upcast(A a)