On Wed, Nov 08, 2017 at 02:48:06PM -0800, Ian Lance Taylor wrote:

[...]
>> So when should I expect the type casting to work?
[...]
> When thinking about Go it's best to avoid concepts that do not apply,
> like derived class, upcast, and downcast.  You can't write
> d.testUnderlyingTypeAsReceiver() because the method is only defined on
> the type S, and d is type []int, not type S.  Passing d to
> testUnderlyingTypeAsParam works because a value of an unnamed type is
> assignable to a value of a named type when the underlying type of the
> named type is the same as the unnamed type.  There is no upcasting or
> downcasting involved.  There is just simple assignment.

Haiyu Zhen, please also note that there are no such thing as "type casting"
in Go: it only has "type conversions" and "type assertions" (which come in
several forms).

-- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to