p
WTF?
g
What is declaration of PageStore? I believe it like:
Copy code
class PagedStore<T>(value: T)
But should be
Copy code
class PagedStore<out T>(value: T)
d
What?
What's the signature of
pager
?
g
Probably like
Copy code
fun pager(store: PagedStore<List<*>>)
👍 1
p
Copy code
class PagedStore<T : List<*>>( ... )
Copy code
fun RenderContext.pager(pagedStore: PagedStore<List<*>>) { ... }
g
It’s quite strange declaration
So this pagedstore is not preserve any types of list?
If so, you need something like this:
Copy code
class PagedStore<out T : List<*>>(value: T)
f
Or cast on the call site.
g
no need to cast on call site
it’s completely valid case and it can be solved by setting correct covariance
p
The
out
doesn exactly help.
g
So it’s not type safe in you case
and it also have sense
p
I cant't change the implementation of RootStore, btw.
g
How RootStore is declared?
g
if you need invarience, you just cannot safely pass it
it’s common problem of data containers
You can do nothing without changing root implementation
For example check declaration of kotlin.collections.Collection, it has
out
to be covariant, but also it still has unsafe invarience (but it safe for cases where it used):
Copy code
public operator fun contains(element: @UnsafeVariance E): Boolean
p
I'll have to better understand the in/out keywords...
g
So in this case only unsafe cast will help, as @Fleshgrinder suggested
If you can chenage pager() decalaration, you can set it to something like:
Copy code
fun pager(store: PagedStore<out List<*>>)
So it will be possible to pass any List there, but you still have to do unsafe cast inside (though, it will not be unsafe)