此方法按预期工作,但我想知道是否有更好的更干净的方法使用现代Java元素编写它。
/**
* Counts how many strings in a given list are shorter than a given min length
* @param strings
* @param minLength
* @return
*/
public int countShortStrings(List<String> strings, int minLength){
int numShort = 0;
for (String str : strings) {
if (str.length() < minLength) {
numShort++;
}
}
return numShort;
}
Run Code Online (Sandbox Code Playgroud) 我在这个包中有一个HillfortStore类:
package org.wit.hillforts.models
Run Code Online (Sandbox Code Playgroud)
在类中混淆了软件包名称(缺少“ s”):
package org.wit.hillforts.model
Run Code Online (Sandbox Code Playgroud)
使用错误的包名称将类导入其他类,它可以正常工作:
import org.wit.hillforts.model.HillfortStore
Run Code Online (Sandbox Code Playgroud)
为了清理问题,我在类及其所有导入的类中修复了名称。现在我得到这个错误。
错误:任务':app:transformClassesWithDexBuilderForDebug'的执行失败。
com.android.build.api.transform.TransformException:java.lang.IllegalStateException:Dex归档文件:仅为.CLASS文件设置.DEX扩展名