JavaFX教程-表示式

梧桐雨—168發表於2008-03-18

表示式

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部落格 ” ,連結:http://blog.itpub.net/13270562/viewspace-209691/,如需轉載,請註明出處,否則將追究法律責任。

相關文章