如何找出哪种类型实现哪种接口 [英] How to find out which types implement which interface

查看:52
本文介绍了如何找出哪种类型实现哪种接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例:

在包io中,类型 ByteReader 定义了包装方法的接口ReadByte() (c byte, err error).

在标准库中查找 哪种类型的最简单方法是什么(即在golang.org/pkg此处列出)对此界面满意吗?

What is the easiest way to find out which types in the standard library (i.e. listed here in golang.org/pkg) satisfy this interface?

这仅仅是经验问题还是有其他帮助吗?

Is this just a matter of experience or is there any other help?

推荐答案

主要是根据经验.无论如何,例如:

Mostly by experience. Anyway, for example:

jnml@fsc-r630:~/go/src/pkg$ egrep -nr '^func (.*) ReadByte\(' *
bufio/bufio.go:165:func (b *Reader) ReadByte() (c byte, err error) {
bytes/reader.go:59:func (r *Reader) ReadByte() (b byte, err error) {
bytes/buffer.go:289:func (b *Buffer) ReadByte() (c byte, err error) {
encoding/xml/xml_test.go:234:func (d *downCaser) ReadByte() (c byte, err error) {
strings/reader.go:58:func (r *Reader) ReadByte() (b byte, err error) {
jnml@fsc-r630:~/go/src/pkg$ 

golang.org网站还具有区分大小写的搜索功能.

And also the golang.org site has a case sensitive search capability.

这篇关于如何找出哪种类型实现哪种接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆