英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论