Addendum:

this may be surprising from the point of view of object-oriented 
programming, class inheritance etc.
but at risk of stating the obvious, in Go there is no class inheritance:
type X time.Time

creates a new type X that is (almost) completely unrelated to time.Time:
1. the new type X does not have the methods of time.Time,
2. and X cannot be used interchangeably with time.Time.

So it makes sense that `types.Type` does not provide any information to 
link them.

the only connection is their identical underlying type, which allows to 
*explicitly* convert between them, i.e. the following works:
var x X
var t time.Time = time.Time(x)
var x2 X = X(t)



On Wednesday, November 20, 2019 at 12:18:28 PM UTC+1, Max wrote:
>
>
> It's part of the language specifications https://golang.org/ref/spec#Types. 
> It says:
> type (
>   B1 string
>   B2 B1
> )
>
> "The underlying type of [...] B1 and B2 is string"
>
> In other words, when you write 
> type X time.Time
> there is absolutely *no direct* connection between the types X and 
> time.Time:
> the only connection is that they both have the same *underlying* type, 
> which is some unnamed struct, as you wrote.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/934eec83-597f-4861-b9bb-71e4846cbe2d%40googlegroups.com.

Reply via email to