如何找出哪些类型实现Golang中的哪个接口?

编程入门 行业动态 更新时间:2024-10-19 13:29:04
本文介绍了如何找出哪些类型实现Golang中的哪个接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

示例:

在包 io 中,类型 ByteReader 定义了一个包装方法 ReadByte()字节,错误错误)。

在标准库中找出 哪些类型的最简单方法是(在golang/pkg 中列出)满足此界面?

这只是一个经验问题或者是否有其他帮助?

解决方案 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字节,err错误){ bytes / buffer.go:289:func(b * Buffer)ReadByte()(c byte,err error){编码/ xml / xml_test.go:234:func(d * downCaser)ReadByte()(c字节,错误错误){ strings / reader.go:58:func(r * Reader)ReadByte()(b字节,err错误){ jnml @ fsc-r630:〜/ go / src / pkg $

此外,golang网站还具有区分大小写的搜索功能。

Example:

In package io the type ByteReader defines an interface that wraps the method ReadByte() (c byte, err error).

What is the easiest way to find out which types in the standard library (i.e. listed here in golang/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$

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

更多推荐

如何找出哪些类型实现Golang中的哪个接口?

本文发布于:2023-11-09 20:50:27,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:接口   类型   Golang

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!