How to cast type alias and interface to int

974 views
Skip to first unread message

so.q...@gmail.com

unread,
Dec 20, 2016, 3:45:33 AM12/20/16
to golang-nuts
How would I cast type alias MyInt and interface Foo, to an int?

Volker Dobler

unread,
Dec 20, 2016, 4:13:35 AM12/20/16
to golang-nuts
Like
    bar = int(foo.(MyInt))
that's: type-assert that foo is a MyInt and convert the MyInt to int.

V. 

so.q...@gmail.com

unread,
Dec 20, 2016, 4:24:25 AM12/20/16
to golang-nuts
Thanks!

Christian von Kietzell

unread,
Dec 20, 2016, 12:02:19 PM12/20/16
to so.q...@gmail.com, golang-nuts
On Tue, Dec 20, 2016 at 12:45:33AM -0800, so.q...@gmail.com wrote:
> How would I cast type alias MyInt and interface Foo, to an int?
>
> https://play.golang.org/p/Sb80WoKh4Y

bar = int(foo.(MyInt))

Chris


--
Nothing to see here. Move along.
Reply all
Reply to author
Forward
0 new messages