- var s1 = 'Hello';
- var s2 = "Hello";
文字列内で {} を使うと、変数値が代入される
- def name = 'Joe';
- var s = "Hello {name}"; // s = 'Hello Joe'
文字列内に条件式を入れることができる
- def answer = true;
- var s = "The answer is {if (answer) 'Yes' else 'No'}";
- // s = 'The answer is Yes'
文字列をつなげる
- def one = "This example ";
- def two = "joins two strings.";
- def three = "{one}{two}"; // join string one and string two
- println(three); // 'This example joins two strings.'
Number and Integer
- def numOne = 1.0; // compiler will infer Number
- def numTwo = 1; // compiler will infer Integer
- def numOne : Number = 1.0;
- def numTwo : Integer = 1;
Boolean
- var isAsleep = true;
- if (isAsleep) {
- wakeUp();
- }
Duration
- 5ms; // 5 milliseconds
- 10s; // 10 seconds
- 30m; // 30 minutes
- 1h; // 1 hour
Void
関数に戻り値がないことを名言するときに使う
- function printMe() : Void {
- println("I don't return anything!");
- }
別に書かなくてもよし
- function printMe() {
- println("I don't return anything!");
- }
Null
Normal value がないことを示す
0や空文字列とは異なるコンパイルがされる
- function checkArg(arg1: Address) {
- if(arg1 == null) {
- println("I received a null argument.");
- } else {
- println("The argument has a value.");
- }
- }
0 件のコメント:
コメントを投稿