miha-x64
04/09/2017, 5:43 PMclass Something<X : Serializable>
.
In Java, within a class with unbound T
type parameter, public void do(Something<T> something)
is an error (since only Something<T & Serializable>
can exist in this context), but Something<? extends T>
is OK. In Kotlin, both Something<T>
and Something<out T>
are errors. Is it by Kotlin design? Or a Java bug? 🙃bjartek
04/09/2017, 6:12 PMmiha-x64
04/09/2017, 6:59 PMmiha-x64
04/09/2017, 7:21 PMpublic class ConvertMeAndCry {
public <X> ConvertMeAndCry(List<? extends X> list) { }
}
bjartek
04/09/2017, 7:21 PMmiha-x64
04/09/2017, 7:33 PMbjartek
04/09/2017, 7:37 PMAndreas Sinz
04/09/2017, 8:59 PMx(Something<? extends T> something)
your T can be any class, even one that is not Serializable
Andreas Sinz
04/09/2017, 9:00 PMT
of x()
has nothing to do with the T
of Something
miha-x64
04/10/2017, 7:35 AMSomething<out T>
into a function, you must obtain it somehow and here its out Serializable
bound will work. And my class don’t want to know anything about it, just out T
. I don’t think Java will allow a mistake here.Andreas Sinz
04/10/2017, 7:43 AMx()
Andreas Sinz
04/10/2017, 7:43 AMmiha-x64
04/10/2017, 7:48 AMorangy
orangy
stanislav.erokhin
Something<? extends T>
is correct type, because may be there is type C
which is subtype of T
and of Serializable
and Something<C>
is subtype of Something<? extends T>
. In kotlin such types (Something<out T>
) forbidden for now by design but we have plans to allow them in future versions.miha-x64
04/10/2017, 9:05 AMstanislav.erokhin
class Foo<T> {
companion object {
operator fun <K, T> invoke(k: K, t: T): Foo<T> = Foo()
}
}
fun main(args: Array<String>) {
Foo<Int, String>(1, "")
Foo(1, "")
}
miha-x64
04/10/2017, 9:21 AMLiveList<? extends MDL>
, which is actually LiveList<? extends MDL & WithId>
, because of class LiveList<T extends WithId>
, and the second one does not mind WithId
and just requires List<? extends MDL>
.
https://github.com/Miha-x64/LiveLists4GreenDAO/blob/master/greenLiveLists/src/main/java/net/aquadc/livelists/greendao/LiveAdapter.java#L31
https://github.com/Miha-x64/LiveLists4GreenDAO/blob/master/greenLiveLists/src/main/java/net/aquadc/livelists/greendao/LiveAdapter.java#L89