How to make Kotlin give API level errors at time of coding, instead of at runtime.
App Gradle file:
minSdkVersion 19
targetSdkVersion 26
Kotlin Code:
//initialisation
var data = getSomedata() //the returned type is Map<String, String>
data.getOrDefault("SomeKey","DefaultValue")
Issue:
Code compiles fine and also able to create signed APK. But when the APK is executed on devices with API 22(Android 5) following error is thrown.
Fatal Exception: java.lang.NoSuchMethodError
Expected beheviour:
If I call the function in java file, lint checking will give following error even before compiling.
Call requires API level 24 (current min is 19): java.util.Map#getOrDefault
CHECKED DUPLICATE
Already checked this question. It is providing reason for the behavior which i have already derived. I need the resolution or work around. As of now I am not sure which all methods would not work at runtime, and users would be reporting those errors which IDE or compiler should have reported.