开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜