Friday, November 12, 2010

Scala Method Syntax

Scala was a little tricky at first, as I got errors when I tried to rely solely on my Java knowledge.

def isLegalMove(x1:Int, y1:Int, x2:Int, y2:Int): Boolean = {code here}

def - this tells Scala that we are defining a method

parameters - these must have the pattern name:type

return value: this follows the parameters, and must be preceded by a colon. if there is no return value, then you follow the parameters with an equals sign

method body: comes after the return value, preceded by an equals sign

No comments:

Post a Comment