- Julia 1.0 Programming Complete Reference Guide
- Ivo Balbaert Adrian Salceanu
- 226字
- 2021-06-24 14:21:49
The type hierarchy – subtypes and supertypes
In Julia, every value has a type, for example, typeof(2) is Int64 (or Int32 on 32-bit systems). Julia has a lot of built-in types, in fact, a whole hierarchy starting from the type Any at the top. Every type in this structure also has a type, namely, DataType, so it is very consistent. typeof(Any), typeof(Int64), typeof(Complex{Int64}), and typeof(DataType) all return DataType. So, types in Julia are also objects; all concrete types, except tuple types, which are a tuple of the types of its arguments, are of type DataType.
This type hierarchy is like a tree; each type has one parent given by the supertype function:
- supertype(Int64) returns Signed
- supertype(Signed) returns Integer
- supertype(Integer) returns Real
- supertype(Real) returns Number
- supertype(Number) returns Any
- supertype(Any) returns Any
A type can have a lot of children or subtypes (a function from the InteractiveUtils package) as follows:
- subtypes(Integer) form 3-element Array{Any,1}, which contains Bool, Signed, and Unsigned
- subtypes(Signed) form 6-element Array{Any,1}, which contains BigInt, Int128, Int16, Int32, Int64, and Int8
- subtypes(Int64) is 0-element Array{Any,1}, which has no subtypes
To indicate the subtype relationship, the operator < is used: Bool <: Integer and Bool <: Any returns true, while Bool <: Char is false. The following is a visualization of part of this type tree:

- Testing with JUnit
- 跟“龍哥”學(xué)C語言編程
- Visual C++數(shù)字圖像模式識別技術(shù)詳解
- The Computer Vision Workshop
- Java性能權(quán)威指南(第2版)
- Drupal 8 Module Development
- Learning Probabilistic Graphical Models in R
- 響應(yīng)式架構(gòu):消息模式Actor實現(xiàn)與Scala、Akka應(yīng)用集成
- Vue.js 2 Web Development Projects
- Citrix XenServer企業(yè)運維實戰(zhàn)
- 零基礎(chǔ)學(xué)Python編程(少兒趣味版)
- 青少年學(xué)Python(第2冊)
- Java程序設(shè)計入門(第2版)
- 零基礎(chǔ)PHP從入門到精通
- Python3從入門到實戰(zhàn)