golang继承,和多态
package main type ST struct{ } func (s *ST)Show(){ println("ST") } func (s *ST)Show2(){ println("ST:Show2()") } type ST2 struct{ ST I int } func (s *ST2)Show(){ println("ST2") } func main() { s := ST2{I:5} s.Show() s.Show2() println(s.I) } golang语言中没有继承,但是可以依靠组合来模拟继承和多态。 但是,这样模拟出来的继承是有局限的,也就是说:在需要多态的时候,需要小心。 $(function () { $('pre.prettyprint code'...阅读全文