# Calling a Method object

**URL:** <https://discourse.julialang.org/t/calling-a-method-object/34112>\
**Category:** General Usage\
**Created:** [February 3, 2020, 11:57am UTC](https://discourse.julialang.org/t/calling-a-method-object/34112 "2020-02-03T11:57:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [February 3, 2020, 11:57am UTC](https://discourse.julialang.org/t/calling-a-method-object/34112/1 "2020-02-03T11:57:51Z")

</div>

Is there any way to do this?

```julia
julia> m = @which sin(1)
sin(x::Real) in Base.Math at special/trig.jl:53

julia> m(20)
ERROR: MethodError: objects of type Method are not callable
Stacktrace:
 [1] top-level scope at REPL[5]:1

```

I don’t mind using internals if necessary…

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [February 3, 2020, 12:14pm UTC](https://discourse.julialang.org/t/calling-a-method-object/34112/2 "2020-02-03T12:14:23Z")

</div>

```julia
julia> args = Any[2.0];

julia> m = @which f(args...);

julia> mi = Core.Compiler.specialize_method(m, Tuple{typeof(f), (typeof.(args))...}, Core.svec())
MethodInstance for sin(::Float64)

julia> function jl_invoke(f, args, mi)
            ccall(:jl_invoke, Any, (Any, Ptr{Any}, Cuint, Any), f, args, length(args), mi)
       end;

julia> jl_invoke(f, args, mi)
0.9092974268256817)

julia> f(args...)
0.9092974268256817

```

is one way, not sure it is the best one (both in terms of correctness and performance) but might get you started. Also look at `jl_lookup_generic`, and `jl_apply_generic`.
