golang-spec icon indicating copy to clipboard operation
golang-spec copied to clipboard

empty method set

Open dakeshi opened this issue 6 years ago • 0 comments

empty method sets 관련 리뷰 토론 내용을 기록합니다.

method sets 챕터에 다음과 같은 문장이 있습니다.

Any other type has an empty method set.

@dakeshi interface {} 의 경우 empty interface 라고 부르는데 interface 타입은 method sets = its interface 이기 때문에 empty method set 이라고도 부를 수 있을 것 같아서요. 저 문장에서 any other type 의 기준점이 되는 type이 어떤 것인지 모르겠습니다.

@jhonghee nterface{} 는 non-empty method set을 가지는 타입에 대해서도 적용가능합니다. Any other type has an empty method set. 은 그 위에 나열된 non-empty method set를 가지는 타입에 반하는 의미로 쓰인 것 같으네요.

예를 들어 기본 타입인 int의 경우 특별히 타입 정의 (type definition)를 통해 이름을 주고 메서드를 선언하지 않는 이상 empty method set을 가지고 있는 것으로 볼 수 있을 것 같습니다.

@dakeshi https://tour.golang.org/methods/14 tour 에도 언급이 되어 있군요.

Every type implements at least zero methods.

Any other type has an empty method set. 이 문장보다 좀 더 명확한 것 같아요.

음. implement 와는 다르게 봐야하나요. tour는 implement을 말하고 empty method set은 type definition 과 method definition 개념으로 봐야할 것도 같기도 하네요.

@jhonghee "at least" 라는 말이 중요한 것 같아요. 0개 이상... 모든 타입이 0개 이상의 메서드를 구현한다고 보기 때문에 interface{} 가 적용 가능한 것이죠.

dakeshi avatar Mar 20 '18 00:03 dakeshi