JSwat supports the evaluation of Java-like expressions. See the built-in "Expression Evaluation" help screen to learn more about them. In short, most of the expressions defined in the JLS are supported.
Expression | Result | Notes |
---|---|---|
123 |
123 |
numeric literals are returned as-is |
true |
true |
boolean literals are returned as-is |
null |
null |
null is returned as-is |
"abc" |
abc |
string literals have their quotes removed |
var |
var's value | variable references are replaced with the variable value |
1 + 1 |
2 |
simple arithmetic expressions are evaluated |
1 == 1 |
true |
equality expression |
i == 1 |
true if i is one |
variable and literal equality expression |
1 != 1 |
false |
equality expression |
i != 1 |
true if i is not one |
variable and literal equality expression |
2 > 1 |
true |
relational expression |
i > 1 |
true if i is greater than one |
variable to literal relational expression |
2.2 >= 2.2 |
true |
relational expression (with floating point operands) |
1 + 2 * 3 |
7 |
operator precedence follows JLS |
(1 + 2) * 3 |
9 |
parentheses override operator precedence |
arr[1 + 1] |
value of third element of arr (an array) | expressions as array indices |
arr[meth(2 + 2)] |
value of nth element of arr (an array) | method invocation as array index |
meth(true, 2 * 3, null) |
method return value | expressions as method arguments |
meth(2 * (3 + 1), a == b, 255 & 32) |
method return value | more complex method invocation |
meth(a == b, meth2(123), 255 & 32) |
method return value | nested method invocation |