Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Interface types in generated code #4

@0xfaded

Description

@0xfaded
reflect.TypeOf(*new(InterfaceFoo))

Will actually promote InterfaceFoo to interface{} before passing it to reflect.TypeOf. Reflect will then inspect the underlying element (nil in this case) resulting in the empty interface type.

Instead, use

reflect.TypeOf(new(InterfaceFoo)).Elem()

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