Skip to content

Abnormal Display in Interface Implementation via Struct Embedding #170

@ZhengweiHou

Description

@ZhengweiHou
// interface
type IPropertySource interface {
	EqualsName(ps IPropertySource) bool
	GetName() string
	GetSource() map[string]any
	GetProperty(key string) any
	ContainsProperty(key string) bool
}

// 部分实现
type NamedPropertySource struct {
	Name string
}

func (n *NamedPropertySource) GetName() string {
	return n.Name
}

func (n *NamedPropertySource) EqualsName(ps IPropertySource) bool {
	return n.Name == ps.GetName()
}

type PropertySource struct {
	NamedPropertySource // 结构体嵌入
	Source map[string]any
}

func (p *PropertySource) GetSource() map[string]any {
	return p.Source
}

func (p *PropertySource) GetProperty(key string) any {
	return p.Source[key]
}

func (p *PropertySource) ContainsProperty(key string) bool {
	_, ok := p.Source[key]
	return ok
}

Expected PropertySource to implement interface IPropertySource

Image

But the actual display:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions