golang type casting from interface int32 to int

12,752 views
Skip to first unread message

Tong Sun

unread,
Oct 8, 2013, 3:11:03 PM10/8/13
to golan...@googlegroups.com
Hi, 

I'm trying to assign a variable of type interface {} int32 to another variable of type int, and here are the all the errors that I'm getting:

- cannot use id (type interface {}) as type int in assignment: need type assertion

- panic: interface conversion: interface is int32, not int

- cannot use id.(int32) (type int32) as type int in assignment

- invalid type assertion: id.(int32).(int) (non-interface type int32 on left)

what's the proper way to do it? 

thanks


Chandru

unread,
Oct 8, 2013, 3:12:54 PM10/8/13
to golan...@googlegroups.com
Try, int(id.(int32))

--
Chandra Sekar.S


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Alexei Sholik

unread,
Oct 8, 2013, 3:14:25 PM10/8/13
to Tong Sun, golang-nuts


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Best regards
Alexei Sholik

Tong Sun

unread,
Oct 8, 2013, 3:32:20 PM10/8/13
to golan...@googlegroups.com, Tong Sun
Thanks a lot everyone!

On Tuesday, October 8, 2013 3:14:25 PM UTC-4, alco wrote:

jego...@gmail.com

unread,
Mar 22, 2016, 7:08:30 PM3/22/16
to golang-nuts, sunto...@gmail.com
THX :))) 

gr.sasi...@gmail.com

unread,
Apr 22, 2019, 10:19:45 AM4/22/19
to golang-nuts
You have to convert int 32 to int .
Reply all
Reply to author
Forward
0 new messages