Home > other >  Golang type for adding method and the inheritance relationship
Golang type for adding method and the inheritance relationship

Time:09-29

In golang if for int type can add methods
 
Type my_int int
Func (n * myint) add myint (x) {
* n +=x
}

Func main () {
Var x my_int=123
X.a dd (100)
}


This way made his my_int int more function on the basis of the method of an add
What is the relationship between inheritance and this way please?

CodePudding user response:

This is a custom type, has nothing to do and inheritance, you can print type

 type MyInt int 

Func (n MyInt) test () {
FMT. Println (reflect the TypeOf (n.) Kind ())//or int, not structure
}

Func main () {
N1:=MyInt (5)
The (n1)
}



  • Related