iex
02/19/2020, 6:38 AMclass Foo<T> {
fun <T> foo(a: T, b: T) = a == b // compiles
}
class MyCallback<T> : DiffUtil.ItemCallback<T>() {
override fun areItemsTheSame(oldItem: T, newItem: T): Boolean =
throw Error("TODO")
override fun areContentsTheSame(oldItem: T, newItem: T): Boolean =
oldItem == newItem // Doesn't compile - "equals in not implemented on T"
}Kune Keiseiie
02/19/2020, 7:19 AMMyCallback<T : Any>?molikuner
02/19/2020, 8:09 AMprintln(MyCallback<String>().areContentsTheSame("a", "b"))
println(Foo<Int>().foo<String>("a", "b"))
As you can see the T of Foo.foo() is a different than the T of Foo . Thats not possible in the MyCallback implementation.iex
02/19/2020, 11:29 AMAny and it didn't change anything, weirdlyiex
02/19/2020, 11:30 AMT in foo is scoped to the function of course. But this doesn't explain the problem, does it? 🤔iex
02/19/2020, 11:31 AMclass Foo<T> {
fun foo(a: T, b: T) = a == b // compiles
}
but it still works... 😄molikuner
02/19/2020, 11:36 AMiex
02/19/2020, 11:47 AMiex
02/19/2020, 11:47 AMDiffUtil used in RecyclerViewAndrew
02/19/2020, 5:20 PMAndrew
02/19/2020, 5:29 PM