type SubClass struct {
SuperClass
other fields...
} type SubClass struct {
SuperClass
other fields...
} struct SubClass {
struct SuperClass super;
// .. other fields ...
}
is valid.BUT what you might not realize is that any method defined on SuperClass (and only defined on SuperClass) can be called on SubClass, but it operates on SuperClass data. This allows SubClass to use SuperClass to help it fulfil an interface for example.
See it in action: http://play.golang.org/p/8kiwu1PlW_
In Go, having final in an embedded struct affect the containing struct seems wrong IMHO- this would allow embeded fields to dictate the behaviour of things that embed them. I don't think most programmers would be happy with adding a field to a struct and as a consequence be prevented from implementing a given method signature.
struct SuperClass {
int foo;
};
struct SubClass {
struct SuperClass super;
};
Then to set the foo item I'd have to do:
struct SubClass bar;
bar.super.foo = 5;Whereas in Go I could say: type SuperClass struct { foo int } type SubClass struct { SuperClass } bar := SubClass{} bar.foo = 5
So, small difference, but I think valid.