是否支持显式的原始类型转换?

huangapple go评论72阅读模式
英文:

Is explicit primitive type casting supported?

问题

有没有办法将自定义原始类型“向下转换”回其原始类型?例如,将type AwesomeType byte转换为byte以供Writer使用?

英文:

Is there a way to "down cast" a custom primitive type back to its original primitive? For example casting type AwesomeType byte to byte for use by a Writer?

答案1

得分: 4

你可以使用你想要的类型进行简单的转换:

var a AwesomeType; b := byte(a)

示例:http://play.golang.org/p/-Sj7zmz6zt

英文:

You can simply cast with the type you want:

var a AwesomeType; b := byte(a)

Example: http://play.golang.org/p/-Sj7zmz6zt

huangapple
  • 本文由 发表于 2013年7月26日 08:20:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/17870919.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定