subtypes
subtypes(T::DataType)
Return a list of immediate subtypes of DataType T. Note that all currently loaded subtypes are included, including those not visible in the current module.
Examples
julia> subtypes(Number)
2-element Array{Any,1}:
Complex{T<:Real}
Real
julia> subtypes(Int)
0-element Array{Any,1}
Here are some examples of how to use the subtypes function:
-
Get subtypes of
Number:julia> subtypes(Number) 4-element Array{Any,1}: Complex Real Integer AbstractFloatThis example returns a list of subtypes of the
Numberabstract type, includingComplex,Real,Integer, andAbstractFloat. -
Find subtypes of a custom defined type:
julia> abstract type Animal end julia> struct Dog <: Animal end julia> struct Cat <: Animal end julia> struct Bird <: Animal end julia> subtypes(Animal) 3-element Array{Any,1}: Dog Cat BirdHere, we define an abstract type
Animal, and three subtypesDog,Cat, andBird. Usingsubtypes(Animal)returns a list of these subtypes. -
Get subtypes from a specific module:
julia> using LinearAlgebra julia> subtypes(AbstractMatrix) 4-element Array{Any,1}: Bidiagonal SymTridiagonal Tridiagonal DiagonalIn this example, we load the
LinearAlgebramodule and find the subtypes of theAbstractMatrixtype from that module.
It's important to note that the returned list includes all currently loaded subtypes, even those not visible in the current module.
Please note that the function subtypes returns an array of type Any, as the subtypes can be any type that is a subtype of the provided DataType.
See Also
assert, backtrace, code_llvm, code_lowered, code_native, code_typed, code_warntype, :@which, compilecache, current_module, eval, finalize, finalizer, fullname, function_module, function_name, include_dependency, InterruptException, invoke, isconst, isdefined, isgeneric, methodswith, method_exists, module_name, module_parent, require, subtypes, unsafe_load, workspace, __precompile__,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.