How to invoke next-most-specific method?


I was recently super pleasantly surprised to discover the invoke method,

invoke(f, types <: Tuple, args…)

Invoke a method for the given generic function matching the specified types, on the specified arguments. The arguments must be compatible with the specified types. This allows invoking a method other than the most specific matching method, which is useful when the behavior of a more general definition is explicitly needed (often as part of the implementation of a more specific method of the same function).

The thing in parentheses is exactly what I want to use invoke for. Specifically, I’ve written some custom broadcast method, inside of which I want to call the generic broadcast that would have been used if my custom one didn’t exist. I could obviously check whatever this generic broadcast is now, but I want something that works even if other definitions of broadcast are added later.

So is there any programmatic way to figure our what this next-most-specific method would be and to invoke it?


I don’t think so. See and (edit)


Thanks, a ton of useful discussion in there. I left a comment in that first issue as the call-next-method mentioned there is exactly what I’m looking for.