Why returns getPassword() from the Object JPasswordField an char[]?

This question already has an answer here:

  • Why is char[] preferred over String for passwords? 17 answers

  • 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'.

    链接地址: http://www.djcxy.com/p/17892.html

    上一篇: 为什么字符[]优先于字符串的密码?

    下一篇: 为什么要从Object JPasswordField返回一个char []?getPassword()?