# \[Beginner\] How do I see the methods on a type I'm extending?

**URL:** <https://discourse.julialang.org/t/beginner-how-do-i-see-the-methods-on-a-type-im-extending/45155>\
**Category:** General Usage\
**Created:** [August 18, 2020, 12:48pm UTC](https://discourse.julialang.org/t/beginner-how-do-i-see-the-methods-on-a-type-im-extending/45155 "2020-08-18T12:48:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![haydenjones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/haydenjones/32/20888_2.png) [@haydenjones](https://discourse.julialang.org/u/haydenjones)\
**Post date:** [August 18, 2020, 12:48pm UTC](https://discourse.julialang.org/t/beginner-how-do-i-see-the-methods-on-a-type-im-extending/45155/1 "2020-08-18T12:48:34Z")

</div>

```julia

struct Thing
  name::AbstractString)
end

struct ThingHolder
  holding::Thing
end

function sayer(t)
  println(x.name)
end

function sayer(t_h)
  print(t_h.holding.name)
end

my_holder = ThingHolder(Thing("hayden"))
sayer(my_holder)
methods(my_holder)

```

I’m trying out 1.5 and this says that `my_holder` has 0 methods. I’m not sure if I understand what `methods()` is doing, I tried the ?julia menu, and I’ve also tried `methods(my_holder, ThingHolder)` and that didn’t help either.

I am curious if Julia is able to distinguish at runtime what methods an object could be called with in this manner.

Thanks!

---

<div class="post-metadata">

**Author:** ![anon37204545](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon37204545](https://discourse.julialang.org/u/anon37204545)\
**Post date:** [August 18, 2020, 1:10pm UTC](https://discourse.julialang.org/t/beginner-how-do-i-see-the-methods-on-a-type-im-extending/45155/2 "2020-08-18T13:10:04Z")

</div>

You have a typo in `Thing`’s name field, as it has `name::AbstractString)` instead of `name::AbstractString`. Also, your second `sayer` definition will overwrite the first, because you’re missing the type to make it distinct.

It should be like this:

```julia
function sayer(t::Thing)
  println(t.name)
end

function sayer(t_h::ThingHolder)
  print(t_h.holding.name)
end

```

You can also remove `print` and `println` here, because the result will be displayed nevertheless.

There is no such list of all methods that accept a specific type, for a very simple reason: there are too many of them (i.e. many methods are type generic).

A few things can help you:

1. check methods to construct a specific type

```julia
julia> methods(ThingHolder)
# 2 methods for type constructor:
[1] ThingHolder(holding::Thing) in Main at REPL[14]:2
[2] ThingHolder(holding) in Main at REPL[14]:2

```

1. check methods of a function which uses multiple dispatch

```julia
julia> methods(sayer)
# 2 methods for generic function "sayer":
[1] sayer(t_h::ThingHolder) in Main at REPL[23]:1
[2] sayer(t::Thing) in Main at REPL[22]:1

```

1. check which method gets called for specific argument types

```julia
julia> which(sayer, [ThingHolder])
sayer(t_h::ThingHolder) in Main at REPL[23]:1

julia> which(sayer, [Thing])
sayer(t::Thing) in Main at REPL[22]:1 

```

---

<div class="post-metadata">

**Author:** ![magister-ludi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/magister-ludi/32/4003_2.png) [@magister-ludi](https://discourse.julialang.org/u/magister-ludi)\
**Post date:** [August 18, 2020, 1:40pm UTC](https://discourse.julialang.org/t/beginner-how-do-i-see-the-methods-on-a-type-im-extending/45155/3 "2020-08-18T13:40:34Z")

</div>

Are you perhaps looking for `methodswith`?

---

<div class="post-metadata">

**Author:** ![haydenjones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/haydenjones/32/20888_2.png) [@haydenjones](https://discourse.julialang.org/u/haydenjones)\
**Post date:** [August 18, 2020, 2:46pm UTC](https://discourse.julialang.org/t/beginner-how-do-i-see-the-methods-on-a-type-im-extending/45155/4 "2020-08-18T14:46:11Z")

</div>

Oh!

Okay, this was very helpful. It makes sense that it can tell me the types if I annotate them properly, I guess I was not really thinking it through that it wouldn’t tell me from inference alone, and I hadn’t realized I was overwriting the definition with an untyped argument, but that makes sense too. I hadn’t considered the point you made about there being too many members in those method tables, but again, it makes perfect sense now that I think about it. Like the + operator probably has dozens if not hundreds of type-dispatched definitions for all sorts of different types, of course.

I didn’t see that typo, it’s not in my code, I was messing around with formatting and it got in there. Thanks though. 🙂

Thanks for such an in-depth reply to such a silly mistake on my part. I read some articles about designing programs with type-dispatch in mind, and I’ve been just practicing and trying to teach my brain to think that way, it’s difficult coming from so much time spent writing classes. For me, anyways.
