Script groovy tag not working properly in Play
Hey guys I am using the script tag.
%{..}%
When I do multiplication it seems to work.
up = wrapBenchmark * upperLimit;
But if I do this.
up = wrapBenchmark + upperLimit;
It seems to add the number as a string to the end. Like a string co开发者_JS百科ncat. What is the issue here? I just want to add two numbers together. It's treating everything as a string. Thanks for the help.
Standard String class (java) has overloaded operator + (string concat), and no overloaded operator * (multiply). So, interpreter casts variables to an integer, when cannot invoke multiply on string objects. And groovy is a dynamically typed language, so parameters sends like strings.
To solve your issue write this
up = wrapBenchmark.toInteger() + upperLimit.toInteger();
精彩评论