Jordan Carlyon
03/30/2020, 6:27 PMsealed class Result<out R>
From the generics documentation
The general rule is: when a type parameterof a classT
is declared out, it may occur only in out-position in the members ofC
, but in returnC
can safely be a supertype ofC<Base>
.C<Derived>
In “clever words” they say that the classSo I can see that type parameteris covariant in the parameterC
, or thatT
is a covariant type parameter. You can think of C as being a producer of `T`'s, and NOT a consumer of `T`’s.T
R
of class Result
can only be returned by Result
, Error
and toString
but what is R
? Is my assumption correct?
I can see here that it is a callable reference
References to functions, properties, and constructors, apart from introspecting the program structure, can also be called or used as instances of function types.
The common supertype for all callable references isBut I am not sure what that is or why it matters here. Is this applicable to this sealed class or is this not considered a callable reference since it is a sealed class? Is the constructor the callable reference and then the return type is, whereKCallable<out R>
is the return value type, which is the property type for properties, and the constructed type for constructors.R
Change<R>
?itnoles
03/30/2020, 6:40 PMJordan Carlyon
03/31/2020, 1:19 AM