https://kotlinlang.org logo
#announcements
Title
# announcements
e

elect

09/23/2017, 6:26 PM
I have several objects to reinterpreter memory:
Copy code
interface reinterpreter<T> {
    operator fun get(index: Int): T
    operator fun set(index: Int, value: T): Any
}
object vec1bData : reinterpreter<Vec1b> {
    override operator fun get(index: Int) = Vec1b(data, index * Vec1b.size)
    override fun set(index: Int, value: Vec1b) = <http://value.to|value.to>(data, index * Vec1b.size)
}
but when I type
Copy code
inline fun <reified T> data():reinterpreter<T> = when (T::class.java) {
        Vec1b::class.java -> vec1bData
}
I get:
required
reinterpeter<T>
, but found
vec1bData
i

ilya.gorbunov

09/23/2017, 9:26 PM
The compiler currently cannot infer that if
T::class.java == Class<X>
then
T == X
, https://youtrack.jetbrains.com/issue/KT-13646
Meanwhile you can clarify the type with a cast
vec1bData as reinterpeter<T>
e

elect

09/24/2017, 7:36 AM
thanks for the link, @ilya.gorbunov, I'll cast
2 Views