Please explain methods priority or specificity in different cases. Where in Julia documentation is it explained? The following line and example in documentation are contradictory.
julia> same_type(x::T, y::T) where {T} = true
same_type (generic function with 1 method)
julia> same_type(x,y) = false
same_type (generic function with 2 methods)
the first method is specific or preferred. Why not following code gives false as output if no method is specific or has priority?
A method can be more specific than another, but when that’s not true, they risk a call throwing an ambiguity MethodError. You’re taking that quote out of a context where ambiguous methods were defined. I’ll save everyone else a click for an accurate quote:
Here the call g(2.0, 3.0) could be handled by either the g(::Float64, ::Any) or the g(::Any, ::Float64) method. The order in which the methods are defined does not matter and neither is more specific than the other. In such cases, Julia raises a MethodError rather than arbitrarily picking a method.