Last active
October 21, 2018 15:21
-
-
Save ParkDongJo/265a56044fa51bd9c95aec03615f1c3a to your computer and use it in GitHub Desktop.
메서드를 정의하다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type counter int | |
func (r counter) inc(v int) int { | |
return int(r) + v | |
} | |
type Person struct { | |
name string | |
age int32 | |
} | |
func (p Person) IsAdult() bool { | |
return p.age >= 18 | |
} | |
func main() { | |
x := counter(3) | |
fmt.Println(x.inc(4)) | |
person := Person{name: "Michał", age: 29} | |
fmt.Println(person.IsAdult()) // true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment