开发者

Why is it not possible to compare session.get with a String var in Play

开发者 https://www.devze.com 2023-03-27 09:40 出处:网络
if (session.get(\"bla\") == \"test开发者_JAVA百科\") {} // is always false wether it is \"test\" or not
if (session.get("bla") == "test开发者_JAVA百科") {} // is always false wether it is "test" or not

if (session.get("bla") == null) {} // works if it is null

I'm not sure what the problem is but in my 1.2.2 installation I'm not able to compare


Comparing objects with == is comparing the objects' references, which means that two strings with identical values might not be the same object. In order to compare the string values, use equals.

if (session.get("blah").equals("test")) {}

I refer you to the Java documentation for String.

0

精彩评论

暂无评论...
验证码 换一张
取 消