go - struct first line is just an interface, what does it mean? -


this question has answer here:

i come across code in go:

type mytype struct {   interfacename   var1  clientinterface1   var2  clientinterface2   id    int } 

what first field mean?

mostly, how sort of inheritance (by composition rather inheritance) achieved in go. check out: https://golang.org/doc/effective_go.html#embedding

this grant outer type (mytype) access inner type's receiver methods (the assigned struct{} since interface).

from go effective:

there's important way in embedding differs subclassing. when embed type, methods of type become methods of outer type, when invoked receiver of method inner type, not outer one

thanks @flimzy , @md2perpe

also, defines anonymous field, variable name same type name.


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -