Scala 基礎

「Scala 基礎」の編集履歴(バックアップ)一覧はこちら

Scala 基礎 - (2009/03/17 (火) 23:43:36) の最新版との変更点

追加された行は緑色になります。

削除された行は赤色になります。

---- object シングルトンなクラス object Util{ def print = { println("Hello") } } class Sample{ def paint={ Util.print() } } ---- var・・・変数=可変 val・・・値=不可変 object SampleApp { def main(args : Array[String]) : Unit = { val a1 = new Test1("test1"); val a2 = new Test2("test2"); //a1.a = "test3";//error a2.a = "test4"; val a3 = new Test3(); var i = a3.a1; //a3.a1 = i;//error i = a3.b1; i = i+1 a3.b1 = i; } } class Test1(val a: String){ } class Test2(var a: String){ } class Test3(){ val a1 = 1; var b1 = 2; } ---- 関数 abstract class Method1 { def method; } class Method2 { def method = {}; } ---- HelloWorld object FirstApp { def main(args : Array[String]) : Unit = { Console.println("hello") } } ---- Application object AppSample extends Application{ println("test"); } ---- タプル tuple def test = { val tuple = ("tap", "le", 10); println(tuple._1); println(tuple._2); println(tuple._3); }
---- object・・・シングルトンなクラス class・・・クラス object Util{ def print = { println("Hello") } } class Sample{ def paint={ Util.print() } } ---- var・・・変数=可変 val・・・値=不可変 object SampleApp { def main(args : Array[String]) : Unit = { val a1 = new Test1("test1"); val a2 = new Test2("test2"); //a1.a = "test3";//error a2.a = "test4"; val a3 = new Test3(); var i = a3.a1; //a3.a1 = i;//error i = a3.b1; i = i+1 a3.b1 = i; } } class Test1(val a: String){ } class Test2(var a: String){ } class Test3(){ val a1 = 1; var b1 = 2; } ---- def 関数名(引数:引数型):戻り値型={} ・・・関数 abstract class Method1 { def method; } class Method2 { def method = {}; } class Point(var x : Int,var y : Int, var z: Int){ def -(p :Point) : Point = { new Point(x -p.x , y -p.y , z -p.z )} def +(p :Point) : Point = { new Point(x +p.x , y +p.y , z +p.z )} override def toString = { "[" + x + ","+ y + "," + z +"]"} } ---- HelloWorld object FirstApp { def main(args : Array[String]) : Unit = { Console.println("hello") } } ---- Application object AppSample extends Application{ println("test"); } ---- タプル tuple def test = { val tuple = ("tap", "le", 10); println(tuple._1); println(tuple._2); println(tuple._3); }

表示オプション

横に並べて表示:
変化行の前後のみ表示:
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。