如何获取类型的所有方法

Fre*_*oen 16 julia

我有一个类型T,如何在REPL中获取所有专门用于此类型的方法?我的动机是T在一个包中定义,T从源代码中可能不容易看到我的意思.

总之,我想要类似的东西

functions(T)
Run Code Online (Sandbox Code Playgroud)

methods已经存在,但它需要的功能,我想了解

Sal*_*apa 25

你需要使用methodswith(T):

help?> methodswith
search: methodswith

  methodswith(typ[, module or function][, showparents])

  Return an array of methods with an argument of type typ. If optional showparents
  is true, also return arguments with a parent type of typ, excluding type Any.

  The optional second argument restricts the search to a particular module or
  function.

julia> type Foo end

julia> methodswith(Foo)
0-element Array{Method,1}

julia> foo(::Foo) = nothing
foo (generic function with 1 method)

julia> methodswith(Foo)
1-element Array{Method,1}:
 foo(::Foo) at none:1
Run Code Online (Sandbox Code Playgroud)