添加理解 Java 中的 NumberFormatException 异常 的链接
This commit is contained in:
parent
85b63c6f8d
commit
ed4af4389d
@ -67,4 +67,42 @@ public class PasswordStoreExamplesUnitTest {
|
|||||||
public void whenCallingToStringOfCharArray_ThenValuesNotEqual() {
|
public void whenCallingToStringOfCharArray_ThenValuesNotEqual() {
|
||||||
assertThat(charPassword.toString()).isNotEqualTo("password");
|
assertThat(charPassword.toString()).isNotEqualTo("password");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void immutableForString() {
|
||||||
|
String stringPassword = "password";
|
||||||
|
System.out.print("Original String password value: ");
|
||||||
|
System.out.println(stringPassword);
|
||||||
|
System.out.println("Original String password hashCode: " + Integer.toHexString(stringPassword.hashCode()));
|
||||||
|
|
||||||
|
String newString = "********";
|
||||||
|
stringPassword.replace(stringPassword, newString);
|
||||||
|
|
||||||
|
System.out.print("String password value after trying to replace it: ");
|
||||||
|
System.out.println(stringPassword);
|
||||||
|
System.out.println("hashCode after trying to replace the original String: " + Integer.toHexString(stringPassword.hashCode()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void immutableForCharArray() {
|
||||||
|
char[] charPassword = new char[]{'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
|
||||||
|
|
||||||
|
System.out.print("Original char password value: ");
|
||||||
|
System.out.println(charPassword);
|
||||||
|
System.out.println("Original char password hashCode: " + Integer.toHexString(charPassword.hashCode()));
|
||||||
|
|
||||||
|
Arrays.fill(charPassword, '*');
|
||||||
|
|
||||||
|
System.out.print("Changed char password value: ");
|
||||||
|
System.out.println(charPassword);
|
||||||
|
System.out.println("Changed char password hashCode: " + Integer.toHexString(charPassword.hashCode()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void accidentallyPassword_print() {
|
||||||
|
String passwordString = "password";
|
||||||
|
char[] passwordArray = new char[]{'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
|
||||||
|
System.out.println("Printing String password -> " + passwordString);
|
||||||
|
System.out.println("Printing char[] password -> " + passwordArray.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user