我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

用String()方法转到接口

Is there a Go interface in the standard library with:

String() string

?

(Similar to how Java has toString() on java.lang.Object)

Perhaps I just didn't search enough but I didn't see one. Wanted to use one that already exists rather than than making my own (though I guess it really makes no difference with Go's type system).

fmt.Stringer is what you're after.

type Stringer interface {
        String() string
}

The closest thing I've seen to Java's toString is fmt#Stringer.

近期文章

  • 使用Go裁剪和创建缩略图
  • golang获取反射类型的类型
  • 在Go Slice或数组中查找唯一项
  • 前往地图与C#字典
  • Go-解码JSON,因为它仍通过net / http流进
  • string.contains和strings.ContainsAny之间的差异
  • 如何从带空格的字符串创建os.exec Command结构
  • 检查变量实现接口而无需编译
  • Golang记录http响应(除了请求)
  • 主题编码的电子邮件(RFC2047)。 解码错误
  • Golang。 从包中仅导入一个文件
  • 如何使用扫描界面将从数据库读取的字符串转换为小写
  • 如何在Go Lang中使用Math / Big
  • 在Go模板范围循环中,每次循环都会在循环外部声明的变量重置吗?
  • 如何仅使用分区键从AWS Dynamodb获取数据?
  • 如何给电子邮件内容添加新的一行
  • Go中的函数冲突
  • Golang mgo获取空对象
  • 如何将HTTP服务部署在TCP4而非TCP6上?
  • 并发文件系统扫描

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华