# Can one override method ambiguity?

**URL:** https://discourse.julialang.org/t/can-one-override-method-ambiguity/10140
**Category:** General Usage
**Tags:** question
**Created:** [April 3, 2018, 3:25pm UTC](https://discourse.julialang.org/t/can-one-override-method-ambiguity/10140 "2018-04-03T15:25:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [April 3, 2018, 3:25pm UTC](https://discourse.julialang.org/t/can-one-override-method-ambiguity/10140/1 "2018-04-03T15:25:06Z")

</div>

I have an API for which the user defines methods for a function, to dispatch on user-defined types.

However, when the second argument is `nothing`, I want this method to return `nothing` _without the user defining a method for the intersection_. MWE:

```julia
abstract type ModelType end
struct Bar <: ModelType end
estimate(::Bar, ::Any) = 1
# I want do dispatch to the one below when possible
# WITHOUT DEFINING estimate(::Bar, ::Void)
estimate(::Any, ::Void) = nothing 
estimate(Bar(), nothing) # this is ambigous

```

Is this possible somehow?

---

<div class="post-metadata">

### Author: ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)
#### Post date: [April 3, 2018, 4:16pm UTC](https://discourse.julialang.org/t/can-one-override-method-ambiguity/10140/2 "2018-04-03T16:16:46Z")

</div>

I constantly run into similar issues, where Julia considers that both are equally specific, so it can’t decide between them, not just with nothing.  
For your API, you couldn’t leave off the last argument for the “nothing” case, or is it that it might not be the last argument?

---

<div class="post-metadata">

### Author: ![Evizero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evizero/32/10118_2.png) [@Evizero](https://discourse.julialang.org/u/Evizero)
#### Post date: [April 3, 2018, 4:24pm UTC](https://discourse.julialang.org/t/can-one-override-method-ambiguity/10140/3 "2018-04-03T16:24:14Z")

</div>

The way i usually work around this is with a function barrier, where the user defines a method for the “inner” function

```julia
estimate(a, b) = inner_estimate(a,b)
estimate(a, ::Void) = nothing

```

example in the wild: [https://github.com/Evizero/Augmentor.jl/blob/master/src/operation.jl#L58-L86](https://github.com/Evizero/Augmentor.jl/blob/master/src/operation.jl#L58-L86)

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [April 4, 2018, 4:02pm UTC](https://discourse.julialang.org/t/can-one-override-method-ambiguity/10140/4 "2018-04-04T16:02:50Z")

</div>

This is so useful and elegant that IMO it deserves a place in the [documentation](https://docs.julialang.org/en/latest/manual/methods/#man-method-design-ambiguities-1).
