Skip to content

Instantly share code, notes, and snippets.

@makiftutuncu
Created December 1, 2015 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makiftutuncu/9f06f363c5955804797b to your computer and use it in GitHub Desktop.
Save makiftutuncu/9f06f363c5955804797b to your computer and use it in GitHub Desktop.
Scala'da tür çıkarımı (type inference) örneği
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)
val k = 'k' // k bir Char olacak.
val l = 5 // l bir Int olacak.
val m = 8L // m bir Long olacak.
val n = false // n bir Boolean olacak.
val o = 3.14 // o bir Double olacak. (e'deki not yüzünden)
val p = "o" // p bir String olacak.
// any2 bir Array[Any] olacak.
val any2 = Array(k, l, m, n, o, p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment