我試圖更改類(Character)的一部分,因此我可以將該結尾更改爲.isDigit作爲示例。就像我可以將型號測試儀更改爲whaterver我想但我不知道我該如何做到這一點。嘗試更改類的一部分Java
public static boolean testText (String password, int length,typeTester) {
boolean test = false;
for (int count = 0; count <= (length-1); count++){
char resultConverted = password.charAt(count);
if (Character.typeTest(resultConverted))
test = true;
}
return test;
}
編輯: 所以現在有辦法做得更好然後就做這樣的事情來分析一個字:
public static boolean testUpperCase (String password, int length) {
boolean upperCase = false;
for (int count = 0; count <= (length-1); count++){
char resultConverted = password.charAt(count);
if (Character.isUpperCase(resultConverted))
upperCase = true;
}
return upperCase;
}
public static boolean testLowerCase (String word, int length) {
boolean lowerCase = false;
for (int count = 0; count <= (length-1); count++){
char resultConverted = word.charAt(count);
if (Character.isLowerCase(resultConverted))
lowerCase = true;
}
return lowerCase;
}
這只是一個問題,確實發現一個更優雅的替代我有什麼到目前爲止。
你想改變在JDK中的'Character'包裝類的代碼? – 2015-02-08 22:18:45
不能在不擴展的情況下添加或修改某個類的方法,並且'Character'是一個final類,因此無法擴展。總之,您將不得不使用'Character'類中的方法來創建一個方法來滿足您的要求。 – 2015-02-08 22:19:01
'Character'類是'final',所以你不能添加任何東西。但是,您可以在該類之外定義自己的'bool isFancyDancy(char)'方法。如果你想添加一些你的問題,請使用「編輯」功能,而不是發表評論。 – 5gon12eder 2015-02-08 22:19:26