0
我試圖理解字符串不變性如何提高安全性。我搜查了許多案件,但沒有給出實際的例子。字符串不變性的安全性
下面是這樣一個例子 -
boolean connect(string s){
if (!isSecure(s)) {
throw new SecurityException();
}
//here will cause problem, if s is changed before this by using other references.
causeProblem(s);
}
在上述情況下,連接方法可以與任何有效的String
被稱爲對於離: - 連接( 「DB2」)或連接(「ORACLE 「)並且該方法將相應地執行。
有人能詳細說明安全性如何增強嗎?
如果它更基本的問題,請原諒。
是什麼讓你覺得'String'不變性增加了安全性? – 2014-11-25 02:45:54
這是一個這樣的博客: - http://java.dzone.com/articles/why-string-immutable-java – user1050619 2014-11-25 02:48:46
這裏是另一個在SO - http://stackoverflow.com/questions/15274874/how-does -java-string-being-immutable-increase-security – user1050619 2014-11-25 02:50:04