gpt4 book ai didi

go - 如何在go中找到实现接口(interface)的类型

转载 作者:数据小太阳 更新时间:2023-10-29 03:33:08 26 4
gpt4 key购买 nike

我需要一个 io.Writer 作为函数。我不知道如何从文件中获取...

我知道接口(interface)是隐式的,所以搜索起来很复杂......

最佳答案

查看os.File文档:它有一个 func (*File) Write方法,这意味着它是一个 Writer。

您可以使用命令 guru 列出实现接口(interface)的所有类型。
值得注意的是,实现查询:

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

关于go - 如何在go中找到实现接口(interface)的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41621525/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com