> Now, I understand this message, and I can cast workItems into
> time.Duration to fix it. What I don't understand is why the first
> example works? Is there something magic about integer literals in Go
> that I'm not aware of?
http://golang.org/doc/go_spec.html#Constants
In your first case, "5" is an untyped constant, so it is coerced to be
whatever type it needs to me. In your second case, the "5" on the
first line is, again, an untyped constant, but you are declaring a
variable at the same time, and that variable needs a type. The default
type of an ideal numeric constant without a decimal point is an int,
so workItems is declared as an int variable.
Dave.
When you do num := 1000, that's equivalent to doing var num int =
1000, and the two become incompatible.
So yes, it's a little magical, but in a good way :)