To fix this method just replace the `Any` with `T`...
# getting-started
k
To fix this method just replace the
Any
with
T
.
t
I'll try, thank you
m
That would defeat the purpose of the function. This is how I would do it:
inline fun <reified T> someCast(data: Any): T? = data as? T
You usually don't pass Class-objects around in Kotlin. You make the type parameter
reified
instead.
t
Good point, but in my case I have reference to
Class
object which the data should be casted to.
k
It it a Class<T> reference?
t
Yes, its some generic Class, and I'm sure the
data
object is an instance of given class.