The Use of def, val, and var in Scala Programming

def is used to create a method.
Example:
def adjustedCosineSimilarity(dotProduct: Double, ratingNorm: Double, rating2Norm: Double) = {
  dotProduct / (ratingNorm * rating2Norm)
}

val is used to create a fixed value or constant (a value that cannot be changed).
Example:
val threshold = 0.5

Meanwhile, var is used to create a variable (a value that can be changed).
Example:
var n = 0

Comments

Popular posts from this blog

Contoh Inheritance (Pewarisan) di Java

Review Singkat Pilihan Transportasi Umum Rute Solo - Wonosobo

Physical address dan Logical Address dalam Jaringan Komputer