Skip to content

proposal: reflect: add Type.IsEmptyInterface #41896

Closed
@cuonglm

Description

@cuonglm

Coming from #41882, @ianlancetaylor suggests adding:

func IsEmptyInterface(t reflect.Type) bool

to reflect package to detect empty interface.

Currently, users (including standard libraries, Google internal code, are relying on reflect.Type.NumMethod() == 0 to check empty interface, which is wrong. After #22075 is fixed, code which uses wrong behavior should be changed to:

reflect.TypeOf((*interface{})(nil)).Elem().Implements(T)

Adding reflect.IsEmptyInterface will help user's migration easier.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions