Scala 基礎

「Scala 基礎」の編集履歴(バックアップ)一覧に戻る

Scala 基礎 - (2009/03/12 (木) 01:13:15) のソース

----
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);
  }
ツールボックス

下から選んでください:

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