Java中that.go_相当于Java在GoLang中传递Object作为方法参数

Go是一种具有许多

functional programming元素的

procedural programming语言.

函数是Go中的第一类类型,您可以创建函数类型的变量,并且可以为这些变量分配函数值,您可以调用它们(存储在它们中的函数值).

所以你可以这样做:

var myprint = fmt.Println

myprint("Hello, playground")

myprint(1, 3.14, "\n", time.Now())

Hello, playground

1 3.14

2009-11-10 23:00:00 +0000 UTC m=+0.000000001

上述myprint变量的优点是它具有与fmt.Println()相同的签名,即:

func Println(a ...interface{}) (n int, err error)

是的,我们还可以创建一个包装函数,如:

func myprint(a ...interface{}) (n int, err error) {

return fmt.Println(a...)

}

更多关于这个主题:

另一种可能性是使用“点导入”,但我建议反对它:

import (

. "fmt"

)

func main() {

Println("Hello, playground")

}

If an explicit period (.) appears instead of a name, all the package’s exported identifiers declared in that package’s 07009 will be declared in the importing source file’s file block and must be accessed without a qualifier.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值