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