Skip to content

Wrong code in the documentation #37

Description

@mosceo

The README.md file has these lines:

MyObjectDef.SetIs((*MyObject)(nil), (MyInterface)(nil))
// ...
ctn.Get(reflect.TypeOf((MyInterface)(nil))).(MyInterface)

Both methods SetIs and reflect.TypeOf accept interface{}, so you lose MyInterface wrapper and the methods will receive nil wrapped in interface{}. You can't pass any interface value to these methods. The right way to send an interface value to reflect.TypeOf is to send a link to an interface, and then call Elem().

This code from the documentation doesn't work, and I can't find a way to teach the container to build some interface value.

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