본문 바로가기
Q&A해결2026년 4월 23일1분 읽기

Go 1.24 generic constraint에서 ~struct 패턴이 컴파일 안 됩니다

G
Go러너
조회 770댓글 1

Go 1.24에서 제네릭 제약을 다음처럼 쓰려고 했는데 컴파일이 안 됩니다.

type Identified interface {
    ~struct{ ID int }
}

func GetID[T Identified](v T) int { return v.ID }

에러는 interface contains type constraints with struct types. 기본형 제약(~int)은 잘 되는데 struct는 왜 안 되는 거죠?

댓글 0

아직 댓글이 없습니다.
Ctrl+Enter로 등록