英文:
How to find types which implement an interface in go
问题
我需要一个 io.Writer 用于一个函数。我不知道如何从文件中获取一个...
我知道接口是隐式的,所以这让搜索变得复杂...
英文:
I need an io.Writer for a function. I don't know how to get one from a file...
I know interface are implicit so it complicated the search...
答案1
得分: 5
请看一下os.File的文档:它有一个func (*File) Write
方法,这意味着它是一个写入器。
你可以使用命令guru
来列出实现某个接口的所有类型。特别是**implements
查询**:
> implements
查询显示被选类型实现的接口,如果被选类型本身是一个接口,则显示实现它的具体类型集合。
>
> 对于值的implements
查询会报告关于表达式类型的相同信息。
>
> 对于方法的implements
查询会显示与该方法相关的抽象或具体方法的集合。
英文:
Look at the os.File documentation: it has a func (*File) Write
method, which means it is a Writer.
You can use the command guru
to list all types implementing an interface.
Notably, the implements
query:
> The implements query shows interfaces that are implemented by the selected type and, if the selected type is itself an interface, the set of concrete types that implement it.
>
> An implements query on a value reports the same information about the expression’s type.
>
> An implements query on a method shows the set of abstract or concrete methods that are related to it
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论