inheritance - 为什么在 Julia 中使用抽象类型关键字?

标签 inheritance julia abstract

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/

相关文章:

css 继承让我失望

mysql - 以 DRY 方式创建事件/存档模型 (Django)

programming-languages - 是什么使Julia不适合通用编程?

arrays - 从映射函数返回多个值

java - 如何使方法参数类型ArrayList<Object>采用不同的对象类型

c++ - 在面向对象编程中分配新内存时处理代码中不同构造函数导致的错误

perl - 是否有一种标准方法可以选择性地从 Perl 父类(super class)继承方法?

constructor - 如果函数使用 convert (Julia),它是构造函数吗?

Java 抽象方法中错误检查的最佳实践

java - 外包 Junit Before 方法