2008年12月11日木曜日

JavaFX 変数型

String
  1. var s1 = 'Hello';  
  2. var s2 = "Hello";  

文字列内で {} を使うと、変数値が代入される
  1. def name = 'Joe';  
  2. var s = "Hello {name}";  // s = 'Hello Joe'  

文字列内に条件式を入れることができる
  1. def answer = true;  
  2. var s = "The answer is {if (answer) 'Yes' else 'No'}";  
  3. // s = 'The answer is Yes'  

文字列をつなげる
  1. def one = "This example ";  
  2. def two = "joins two strings.";  
  3. def three = "{one}{two}";   // join string one and string two  
  4. println(three);   // 'This example joins two strings.'  



Number and Integer
  1. def numOne = 1.0;  // compiler will infer Number  
  2. def numTwo = 1;   // compiler will infer Integer  
  3.   
  4. def numOne : Number = 1.0;  
  5. def numTwo : Integer = 1;  



Boolean
  1. var isAsleep = true;  
  2.   
  3. if (isAsleep) {  
  4.   wakeUp();  
  5. }  



Duration
  1. 5ms;   // 5 milliseconds  
  2. 10s;   // 10 seconds  
  3. 30m;  // 30 minutes  
  4. 1h;    // 1 hour  



Void
関数に戻り値がないことを名言するときに使う
  1. function printMe() : Void {  
  2.   println("I don't return anything!");  
  3. }  

別に書かなくてもよし
  1. function printMe() {  
  2.   println("I don't return anything!");  
  3. }  



Null
Normal value がないことを示す
0や空文字列とは異なるコンパイルがされる
  1. function checkArg(arg1: Address) {  
  2.   if(arg1 == null) {  
  3.     println("I received a null argument.");  
  4.   } else {  
  5.     println("The argument has a value.");  
  6.   }  
  7. }  

0 件のコメント:

コメントを投稿