It would just mean that all embedded struct types introduce a new type
named "(parent struct type name).(field name)|, that you could use as if it
were any other type (albeit with a dot, not currently allowed in type
names).

Sometimes it's nice to define a type as part of another type to see a
deeper structure in one go rather than having to scan around a
file/different files, but right now those embedded types are incorrigible
for most uses, e.g. defining methods or passing around as exported types.

On 24 August 2016 at 23:15, Jan Mercl <[email protected]> wrote:

>
>
> On Thu, Aug 25, 2016, 00:08 Sam Salisbury <[email protected]> wrote:
>
>> Would it be nice or nasty for this to work? https://play.golang.org/
>> p/iCTKx3gF_2
>>
>> Copy-pasted:
>>
>> type Thing struct {
>> Embedded struct {
>> Name string
>> }
>> }
>>
>> func main() {
>> x := Thing.Embedded{Name: "Barry"}
>> fmt.Println(x.Thing.Name)
>> // output:
>> // Barry
>> }
>>
>>
>> Seems it would be useful to me to be able to do this sometimes,
>> especially when consuming other people's code that uses embedded struct
>> types.
>>
>
> A field is either named or anonymous. The later case means embedding. But
> what a named embedded field would even stand for?
>
> --
>
> -j
>

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to