五月七号日报

今日学习内容

Go语言中的接口与反射

1.1接口概念:通过它可以实现很多面向对象的特性。接口提供了一种方式来 说明 对象的行为

package main

import "fmt"

type stockPosition struct {
	ticker 	   string
	sharePrice float32
	count      float32
}

func(s stockPosition) getValue() float32{
	return s.sharePrice*s.count
}

type car struct {
	make string
	model string
	price float32
}

func (c car) getValue() float32{
	return c.price
}

type valuable interface {
	getValue() float32
}

func showValue(asset valuable){
	fmt.Printf("Value of the asset is %f
", asset.getValue())
}

func main() {
	var o valuable=stockPosition{"GOOG", 577.20, 4}
	showValue(o)
	o = car{"BMW", "M3", 66500}
	showValue(o)

}

1.2接口嵌套接口:一个接口可以包含一个或多个其他的接口,这相当于直接将这些内嵌接口的方法列举在外层接口中一样

上午听了肖峰讲解了墙的相关知识与产品开发流程,下午搭建了Go的开发环境

原文地址:https://www.cnblogs.com/swtczb/p/11632666.html