什么是“任何”输入GO 1.18?
在Visual Studio代码中,自动完成工具(我认为是gopls
?)给出以下模板:
m.Range(func(key, value any) bool {
})
哪里m
是sync.map
。 类型尚未识别,而是放在那里。
什么是任何
?我可以将自己想要的类型放在我想要的1.18上做隐式对我的类型转换吗?例如:
m.Range(func(k, v string) { ... })
哪个将给出k
,v
作为回调内的字符串,而无需键入cast自己?
In Visual Studio Code, the auto-complete tool (which I presume is gopls
?) gives the following template:
m.Range(func(key, value any) bool {
})
where m
is a sync.Map
. the type any
is not recognized, but is put there.
What is any
? Can I put the type I want and hope Go 1.18 to do implicit type conversion for me? For example:
m.Range(func(k, v string) { ... })
which will give k
, v
as string inside the callback, without having to do type cast myself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
任何
是新的 predeclared标识符和类型的
类型别名接口{}
。它来自问题49884 , cl 368254 和提交2580D0E 。
问题提到了
接口{}
/任何
:any
is a new predeclared identifier and a type alias ofinterface{}
.It comes from issue 49884, CL 368254 and commit 2580d0e.
The issue mentions about
interface{}
/any
: