Go nil 인터페이스 값

Jmnote (토론 | 기여)님의 2023년 10월 18일 (수) 21:26 판
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

Nil interface values
Go nil 인터페이스 값
package main

import "fmt"

type Person interface {
	SayHello()
}

type Student struct{}
func (s *Student) SayHello() {
	fmt.Println("Hello")
}

func main() {
	var student *Student = nil
	var person Person = student
	describe(person)
	person.SayHello()
}

func describe(person Person) {
	fmt.Printf("(%v, %T)\n", person, person)
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}