Eugenio
10/06/2015, 2:49 PMdesseim
10/06/2015, 4:06 PMapatrida
10/06/2015, 4:10 PMapatrida
10/06/2015, 4:10 PMapatrida
10/06/2015, 4:10 PMapatrida
10/06/2015, 4:11 PMdesseim
10/06/2015, 4:13 PMvmironov
10/06/2015, 4:21 PMpublic inline fun <reified V : View?> View.find(id: Int): V {
val result = findViewById(id)
if (result == null && !V::class.isNullable) {
throw IllegalArgumentException("Unable to find view ${view.resources.getResourceName(id)}")
}
return result as V
}
vmironov
10/06/2015, 4:21 PM// optional, returns null
val optional = view.find<View?>(some_invalid_id)
// required, throws an exception
val required = view.find<View>(some_invalid_id)
apatrida
10/06/2015, 4:31 PMKtype
should have isNullable or isOptional, check itapatrida
10/06/2015, 4:31 PMapatrida
10/06/2015, 4:31 PMvmironov
10/06/2015, 4:41 PMV::class.defaultType.isMarkedNullable
? Looks like it always returns false
udalov
vmironov
10/06/2015, 4:55 PMudalov
apatrida
10/06/2015, 4:57 PMval s: String?
means s
is, but String still is just a classudalov
desseim
10/06/2015, 5:00 PMClass
instance which the compiler treats as of type Class<List<String>>
from an instance (e.g. listOf<String>().javaClass
), isn’t there really a way to do the same without instantiating an object ?apatrida
10/06/2015, 5:00 PMapatrida
10/06/2015, 5:01 PMapatrida
10/06/2015, 5:01 PMudalov
List::class.java as Class<List<String>>
desseim
10/06/2015, 5:01 PMapatrida
10/06/2015, 5:02 PMfullType<List<String>>().type
apatrida
10/06/2015, 5:02 PMapatrida
10/06/2015, 5:02 PMClass<T>
it will be a Type
or specifically a ParameterizedType
apatrida
10/06/2015, 5:03 PMClass
vs Type
apatrida
10/06/2015, 5:03 PMType
that has thatapatrida
10/06/2015, 5:03 PM