The Use of def, val, and var in Scala Programming
def is used to create a method.
Example:
val is used to create a fixed value or constant (a value that cannot be changed).
Example:
Meanwhile, var is used to create a variable (a value that can be changed).
Example:
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
Post a Comment