This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| println("Hello world!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * A base trait for custom enumerations | |
| * | |
| * <ol> | |
| * <li>Have an abstract super class E for all your enum items.</li> | |
| * <li>Generate case objects for each enumeration item of type E.</li> | |
| * <li>Then add them to values set when you implement it.</li> | |
| * </ol> | |
| * | |
| * Example: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object MerhabaScala { | |
| def main(args: Array[String]): Unit = { | |
| println("Merhaba Scala!") | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def topla(sayi1: Int, sayi2: Int): Int = sayi1 + sayi2 | |
| def toplamCiftMi(sayi1: Int, sayi2: Int): Boolean = { | |
| val toplam: Int = topla(sayi1, sayi2) | |
| val mod2: Int = toplam % 2 | |
| mod2 == 0 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| case class Insan(yas: Int) | |
| object NedenScala { | |
| def main(args: Array[String]) { | |
| val insanlar = for (i <- 1 to 10) yield Insan(scala.util.Random.nextInt(30) + 5) | |
| println("İnsanlar:") | |
| insanlar foreach println | |
| println("Yaşları toplamı:") | |
| println(insanlar.foldLeft(0)(_ + _.yas)) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Insan { | |
| private int yas; | |
| public Insan(int yas) { | |
| this.yas = yas; | |
| } | |
| public int yas() { | |
| return yas; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val a: Char = 'a' | |
| val b: Int = 3 | |
| val c: Long = 5 | |
| val d: Boolean = true | |
| // Scala Double'ı Float'a tercih eder. Özellikle Float istediğimiz için tür dönüşümü yapıyoruz. | |
| val e: Float = (3.14).asInstanceOf[Float] | |
| val f: String = "e" | |
| val any1: Array[Any] = Array(a, b, c, d, e, f) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def dogru(a: String, b: Int, c: Boolean): Long = { | |
| // Burada Long türünde bir değer olacak. | |
| } | |
| // Metodun dönüş değerinin türü de çıkarımla bulunabilir çünkü gövdedeki son ifadenin değeri geri döndürülecek. | |
| // Haliyle metodun dönüş değerinin türü de bu son ifadenin değerinin türü olacak. | |
| // Dolayısıyla metod imzasından dönüş türünü atabiliriz. | |
| def buDaDogru(a: String, b: Int, c: Boolean) = dogru(a, b, c) | |
| // Bu hata verecek çünkü Scala statik türlü. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var sayi: Int = 6 | |
| var metin = "Sayı çift mi?" | |
| var ciftMi: Boolean = _ | |
| println("Sayı: " + sayi) | |
| println(metin + " " + ciftMi) | |
| ciftMi = sayi % 2 == 0 | |
| println("Tekrar bak.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val sayi: Int = 6 | |
| val metin = "Sayı çift mi?" | |
| // Bu hata verecek. | |
| val ciftMi: Boolean = _ | |
| // Bu da hata verecek. | |
| sayi = 5 |
OlderNewer