public class MyClass extends Activity {
public static final String DEFAULT_ID = "def";
public static final LinkedHashSet<String> DEF_IDS = new LinkedHashSet<>(Arrays.asList(DEFAULT_ID));
private boolean isDefault(String currentId) {
Log.v(TAG,"isdefault("+currentId+") = " + DEF_IDS.contains(currentId));
return DEF_IDS.contains(currentId);
}
}
在日誌返回true?如果DEF_IDS不包含「profile0」,它爲什麼說它包含?LinkedHashSet.contains()時,它應該返回false
是它'profile0'(變量)或' 「PROFILE0」'? – dotvav
這意味着在調用'isDefault()'之前有人把它放在這裏。原因可能是'DEF_IDS'是靜態的並且在類之間共享。 –
我剛剛測試了你的代碼,[它按預期工作](https://ideone.com/zszk17)。其他的一定是錯的。 – Tunaki