首页 > Linux操作系统 > Linux操作系统 > JavaFX教程-表达式
JavaFX支持如下操作符:
| 操作符 | 含义 | Java等价物 |
| 关系操作符 | ||
| == | equality | == |
| <> | inequality | != |
| < | less than | < |
| > | greater than | > |
| <= | less than or equal | <= |
| >= | greater than or equal | >= |
| 布尔操作符 | ||
| and | logical and | && |
| or | logical or | || |
| not | logical negation | ! |
| 算术操作符 | ||
| + | addition | + |
| - | subtraction; unary negation | - |
| * | multiplication | * |
| / | division | / |
| % | remainder | % |
| += | add and assign | += |
| -= | subtract and assign | -= |
| *= | multiply and assign | *= |
| /= | divide and assign | /= |
| %= | remainder and assign | %= |
| 其它操作符 | ||
| sizeof | array length | n/a |
| indexof | ordinal position | n/a |
| if e1 then e2 else e3 | conditional expression | e1 ? e2 : e3 |
| select | list comprehension | n/a |
| foreach | list comprehension | n/a |
| new | allocation | new |
| op() | function/operation call | n/a |
| x.op() | member function/operation call | x.op() |
| instanceof | type check | instanceof |
| this | self access | this |
| . | attribute access, context access | ., n/a |
| bind [lazy] | incremental [lazy] evaluation | n/a |
| : | eager initialization | n/a |
| [] | array selection | [] |
| format as | String formatting | n/a |
| <<>> | Identifier quotes | n/a |
| {} | String expression | n/a |
| (expr) | grouping | (expr) |
| reverse | reverses a list | n/a |
| [number1,next..number2]<!-- | numeric range | n/a |
一些示例:
import java.lang.System;
import java.lang.Math;
var x = 2;
var y = 4;
var a = true;
var b = false;
System.out.println(x == y); // prints false
System.out.println(x <> y); // prints true
System.out.println(x < y); // prints true
System.out.println(x > y); // prints true
System.out.println(x >= y); // prints false
System.out.println(x <= y); // prints true
System.out.println(x + y); // prints 6
System.out.println(x - y); // prints -2
System.out.println(x * y); // prints 8
System.out.println(x / y); // prints 0.5
System.out.println(x % y); // prints 2
System.out.println(a and b); // prints false
System.out.println(a or b); // prints true
System.out.println(not a); // prints false
System.out.println(sizeof [x,y]); // prints 2
System.out.println([x,y][indexof . == 0]); // prints 2
System.out.println(if a then x else y); // prints 2
System.out.println(select q from q in [x, y] where q > 3); prints 4
System.out.println(foreach(q in [x, y] where q < 3) q); prints 2
System.out.println(Math.max(x, y)); // prints 4
System.out.println("abc".toUpperCase()); // prints ABC
System.out.println(x instanceof Number); // prints true
x = 10;
System.out.println(x); // prints 10
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/13270562/viewspace-209691/ ,如需转载,请注明出处,否则将追究法律责任。