go的反射有什么不同
golang网络字节与基本类型转换

golang的继承不是继承

妙音 posted @ 2021年4月12日 19:46 in golang , 1975 阅读
 

问题

 
struct嵌套,内层struct方法访问同名的属性,这个属性是谁的?
 

示例

 
package main

import (
"fmt"
)

type ProductA struct{
Name string
}

func (p *ProductA) PrintName(){
fmt.Println("a:", p.Name)
}

type ProductB struct{
ProductA
Name string
Level string
}

func main() {
    b := ProductB{
Name: "name-b",
Level: "level",
}
b.PrintName()
}
// 仍然是ProductA的
//打印 a:
 

总结

 
1. go没有继承,只有组合
2. 只是提供了类似继承的便捷访问方式,不要被所谓的”继承“误导
 
Avatar_small
briansclub 说:
2023年7月03日 21:36

Appreciate you sharing great post. Fantastic.

Avatar_small
Falcon Media Marketi 说:
2023年8月19日 04:14

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoy every little bit of it and I have you bookmarked to check out new stuff you post.

Avatar_small
instrument 说:
2023年8月19日 17:25

Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with extra information? It is extremely helpful for me

Avatar_small
mg comet price 说:
2023年9月14日 04:35

I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

Avatar_small
how2invest 说:
2023年9月24日 04:37

I was exceptionally satisfied to find this site.I needed to thank you for this extraordinary read!! I most certainly partaking in every single piece of it and I have you bookmarked to look at new stuff you post.

Avatar_small
Know Near Me 说:
2023年10月12日 04:09

This is a really good article. I think this is one of the best entries I’ve ever read. Your work is outstanding and motivating. This is a really good article. I think this is one of the best entries I’ve ever read. Your work is outstanding and motivating.

Avatar_small
Podcast 说:
2023年11月03日 04:42

I’m happy to find so many useful info here in the post, thanks for sharing. I love the variety of content available on your website. I’ll bookmark your blog and take the feeds also!

Avatar_small
wellhealthorganic vi 说:
2023年11月29日 01:29

Wonderful article! plus its information and I positively bookmarked to this site because here I always get an amazing information as I expect. Thanks for this to share with us.

Avatar_small
Best Home Around 说:
2023年12月12日 03:30

Very Helpful information! Fortunately, I found your website unintentionally and I am shocked that this coincidence did not occur earlier! I bookmarked it.

Avatar_small
The Tech Towns 说:
2023年12月22日 02:28

I at long last found what I was searching for! I'm so blissful. Your article is the thing I've been searching for quite a while. I'm glad to think that you are this way. Respecting the time and exertion you put into your site and itemized data you offer. Much appreciated.

Avatar_small
ZYN Rewards 说:
2024年1月14日 03:48

Actually an incredible expansion. I have perused this great post. Gratitude for sharing data about it. I truly like that. Much obliged so part for your assemble.

Avatar_small
99math 说:
2024年2月03日 04:17

I wanted to thank you for this excellent read!! Very informative post! There is a lot of information here. I have you bookmarked your site to check out the new stuff you post. I really appreciate it..


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter