After upgrading to compile SDK
version 26, all findViewById
showing error:
not enough information to infer parameter T in fun findViewById(id: Int): T!
After upgrading to compile SDK
version 26, all findViewById
showing error:
not enough information to infer parameter T in fun findViewById(id: Int): T!
It's Kotlin some type expected error fix it
Because you are confusing
java
withkotlin
, with android studio3.0
you can usekotlin
instead ofjava
syntax or you can use both as mentioned on Android official blogAlso read about
Get Started with Kotlin on Android
Update : The function signature
View findViewById(int id)
has been upgraded to
<T extends View>T findViewById(int id)
mean it's applying the inference mechanism for return type whereT extends View
mean the View or it's sub-typesNote : So as mentioned initially ,Applying cast still won't generate any error but just a lint warning for using unnecessary cast but could be a bug in kotlin type inference but not in java.
In pure Java you will have for example
In Kotlin you can go with this
This is because as of Android O, we don't need to cast it. There are a few options. Replace:
With either:
Or:
If you want to know what happened under the covers, as of O underlying method changed to