Methods can be implemented only on wrapper types and structs.
Working Example
package main
import "fmt" as fmt
import "strconv" as strconv
struct Person {
String FirstName
String LastName
Int Money
Bool Happy
}
def String getSummary(Person person) {
let fullName = person.FirstName + " " + person.LastName
return fullName + " has $" + strconv.Itoa(person.Money) + ". It is " + strconv.FormatBool(person.Happy) + " that he is happy."
}
fun Unit main() {
let person = Person{FirstName = "John", LastName = "Doe", Money = 10000, Happy = true}
fmt.println(person.getSummary())
}
package main
import fmt "fmt"
import strconv "strconv"
type person struct {
happy bool
money int
lastName string
firstName string
}
func (person person) getSummary() string {
fullName := person.firstName + " " + person.lastName
// Eliminates any 'unused variable' errors
_ = fullName
return fullName + " has $" + strconv.Itoa(person.money) + ". It is " + strconv.FormatBool(person.happy) + " that he is happy."
}
func main() {
person := person{firstName: "John", lastName: "Doe", money: 10000, happy: true}
fmt.Println(person.getSummary())
// Eliminates any 'unused variable' errors
_ = person
}