Why returns getPassword() from the Object JPasswordField an char[]?
This question already has an answer here:
Well. The point is, that the lifecycle of a String is a little bit special. All Strings are stored in a String Pool. When the reference is lost (dereferencing) for example when you say String = null;
the String is still alive in the internal string pool (and can be accessed in a kind of way I don't know). That's the reason why passwords are stored in char[]. Since these objects are 'normal'.
上一篇: 为什么字符[]优先于字符串的密码?