The following Go code:
package main
import "fmt"
type Polygon struct {
sides int
area int
}
type Rectangle struct {
Polygon
foo int
}
type Shaper interface {
getSides() int
}
func (r Rectangle) getSides() int {
return 0
}
func main() {
var shape Shaper = new(Rectangle)
var poly *Polygon = new(Rectangle)
}
causes this error:
cannot use new(Rectangle) (type *Rectangle) as type *Polygon in assignment
I can't assign a Rectangle instance to a Polygon reference, like I can in Java. What is the rationale behind this?