Julia 中“抽象类型”的目的是什么?除了使用继承层次结构的类型之外,还有其他用途吗?
abstract Animal
type Dog <: Animal
sound
color
end
type Bird <: Animal
sound
color
end
如果它不提供继承属性和方法的能力,这样做的目的是什么?
最佳答案
大概值reading through the manual为此,因为它们有很多用途。
引用手册中的一个例子:
Abstract types allow the construction of a hierarchy of types, providing a context into which concrete types can fit. This allows you, for example, to easily program to any type that is an integer, without restricting an algorithm to a specific type of integer.
关于inheritance - 为什么在 Julia 中使用抽象类型关键字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36267586/