【发布时间】:2012-12-30 21:55:54
【问题描述】:
对于 Java 的 Console 对象,尤其是 readPassword() 方法,我遇到了可笑的困难。
我有当前代码要读入一个密码,两次,然后循环直到两个密码相同:
do {
dbPasswordOne = userInput.readPassword("Enter a password for the bookstall: ");
System.out.println(dbPasswordOne.toString());
dbPasswordTwo = userInput.readPassword("Re-enter the password: ");
System.out.println(dbPasswordTwo.toString());
} while (!Arrays.equals(dbPasswordOne, dbPasswordTwo));
在我看来,这应该可以正常工作(打印只是为了调试目的。但是,这是我在 Linux 终端中得到的输出:
Enter a password for the bookstall:
[C@9e4acce
Re-enter the password:
[C@40d0d75
无论我输入什么,每次我运行它总是相同的两个无意义的字符串。任何帮助将不胜感激。
【问题讨论】:
-
“dbPasswordOne 和 dbPasswordTwo 的类型是什么?看起来您正在尝试打印一个对象(不是字符串)。