πMethods
Method Syntax
def <methodName>(<receiverParamName>: ReceiverType, Parameters): <ReturnType> {
<method body>
}
For syntax of Parameters
- Common placeholders throughout documentation
Methods can be implemented only on wrapper types and structs.
Working Example
package main
import "fmt" as fmt
import "strconv" as strconv
struct Person {
FirstName: String
LastName: String
Money: Int
Happy: Bool
}
def getSummary(person: Person): String {
let fullName = person.FirstName + " " + person.LastName
return fullName + " has $" + strconv.Itoa(person.Money) + ". It is " + strconv.FormatBool(person.Happy) + " that he is happy."
}
fun main(): Unit {
let person = Person{FirstName = "John", LastName = "Doe", Money = 10000, Happy = true}
fmt.println(person.getSummary())
}
Last updated