In Java and C#, the Object
class is implicitly parent of all classes that are defined. Is there something similar in go?

我们在Golang中有与Java和C#对象相同的东西吗?
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- dplase3140 2016-07-27 04:25关注
There is no inheritance in Go.
I think you are looking forinterface
: Go: What's the meaning of interface{}?but if you need something similar to Object (not Class) you may use
interface
:Variables of interface type also have a distinct dynamic type, which is the concrete type of the value assigned to the variable at run time (unless the value is the predeclared identifier nil, which has no type). The dynamic type may vary during execution but values stored in interface variables are always assignable to the static type of the variable.
var x interface{} // x is nil and has static type interface{} var v *T // v has value nil, static type *T x = 42 // x has value 42 and dynamic type int x = v // x has value (*T)(nil) and dynamic type *T
and:
Interface types:
An interface type specifies a method set called its interface. A variable of interface type can store a value of any type with a method set that is any superset of the interface. Such a type is said to implement the interface. The value of an uninitialized variable of interface type is nil.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报