And I dont understand why the IDE says a Nothing i...
# announcements
c
And I dont understand why the IDE says a Nothing is required
d
*
is equivalent to
in Nothing
when writing values.
*
means you don't know what the type is, so you have no way of putting any value in, since there is no way to prove that it matches the actual type (since you don't know what the actual type is).
s
When you use the wildcard as a type-parameter value, you can basically only really use the methods and properties of that interface of class that don’t need that type-parameter at all. E.g
MutableList<*>
will be problematic when trying to call
add
(and even call
get
, since it’ll return an
Any?
), but calling
size
or
toString()
is fine….
c
Then how can i write
Copy code
val middleWareMap: Map<KClass<*>,Middleware<AppState, *any class extending action*,  *any class extending action*>>
s
Map<KClass<*>, Middleware<AppState, Action, Action>
?
e
Define the middleware interface as
interface Middleware<S: State, out A: Action, out A2: Action> ...
Because you state that A and A2 are out generics and have a base type of Action, it means you can put Middleware instances into a map and the A and A2 types can specifically be subtypes of Action
s
^^^
A
should be contra-variant (
in
) at best (and
A2
can be co-variant (
out
))
c
OOk thanks :))
s
Or all of them can be invariant (no
in
nor
out
) if you are not interested in the assignability of sub-types of
Middleware
based its type-parameters
A
and
A2
to a plain
Middleware
type.