伙计们,为什么我不能在我的 Android Studio 项目中使用 HashMap 替换方法?
private HashMap<Integer, Integer> scoreLine = new HashMap<Integer, Integer>();
scoreLine.put(0, 22;
scoreLine.put(1, 46);
scoreLine.put(2, 89);
scoreLine.replace(1, 49); // I can't use this
scoreLine.replace(1, 46, 49); // I can't use this either
即使我可以使用put方法添加项目
这是我的 gradle.build(只是代码的一部分)
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.practiceprojectweekend"
minSdkVersion 22
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
如你所见,我确实设置了当前的minSdkVersion为22
并且该替换方法需要最低级别 24
我确实将 minSDK 替换为 24
但是后来我无法不使用我的 Android 设备运行该应用程序
有没有办法在不改变 minSdkVersion 的情况下解决这个问题?
最佳答案
如果不更改 minSdkVersion,就无法解决这个问题。 replace(K, V)
在SDK 24版本中添加,replace(K, V, V)
在SDK 26版本中添加。
如评论中所述,put
将替换现有值。
您可以在 docs page 中查看更多详细信息
关于java - 无法使用 HashMap 替换方法 : call require api level 24 (current min is 22):java. util.HashMap#replace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50122383/