My project uses Array#sort that requires API level 24 (Android 7.0)
_tmp.sort((left, right) -> { ... };
But I have also minSdkVersion 21
(Android 5.0)
When I run that code on Android 6.0 Emulator, the following exception is thrown:
... Caused by: java.lang.NoSuchMethodError: No interface method sort(Ljava/util/Comparator;)V in class Ljava/util/List; or its super classes (declaration of 'java.util.List' appears in /system/framework/core-libart.jar)
I have found that other users asked about this exception: java.lang.NoSuchMethodError: No interface method sort(Ljava/util/Comparator;) exception in sorting arraylist android
Any good way to Android Studio warns that .sort
is not workable on OSes earlier than Android 7.0? like APIs having @RequiresApi
?
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { ... }