The section Interface checks from Effective Go recommends
var _ json.Marshaler = (*RawMessage)(nil)
as a compile-time check that RawMessage
implements Marshaler
.
I get how the assignment does the type check but what does the right side actually mean?
Ok, I figured it out. It creates a new *RawMessage
(pointer to RawMessage
) that is nil
by casting nil
to *RawMessage
. I would have expected
*RawMessage(nil)
but that doesn't work because the cast conversion seems to take precedence over the pointer operator, so it would become a dereference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With