如题在lesson目录下有
package lesson
type Rectangle struct {
Width, Height float64
}
func (r Rectangle) Area() float64 {
return r.Width * r.Height
}
以及
package lesson
import (
"math"
)
type Circle struct {
Radius float64
}
func (c Circle) Area() float64 {
return c.Radius * c.Radius * math.Pi
}
我现在写了一个基础的
package lesson
import (
"fmt"
)
func Say(s string) {
fmt.Println(s)
}
想让计算长方形和圆的对象都有say这个方法,在import的时候回说不允许import 循环,请问遇到这种情况,在同名package下应该怎么解决?
同一个package下引用方法不用前置包名。不知道你是不是下面这个意思?
参考代码: