例如,假设我为AbstractFloat
写了一个函数,我想知道这个方法定义的影响,如何查看Base中AbstractFloat
的所有子类型?
最佳答案
您正在寻找 subtypes
:
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.
julia> subtypes(AbstractFloat)
4-element Array{Union{DataType, UnionAll},1}:
BigFloat
Float16
Float32
Float64
但有趣的是,Base
中只有一个:
julia> subtypes(Base, AbstractFloat)
1-element Array{Union{DataType, UnionAll},1}:
BigFloat
顺便说一句,PlotRecipes.jl 中有一个不错的食谱可视化类型树:
关于julia - 如何在 Julia Base 中找到抽象类型的子类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46851485/