None. Even with Java's typesystem you can know whether the thing or things you have in your hand implements some interface or not ("callable" in this case) at compile time. You can't ask this question because you can't not already know the answer.<p>I'm not speaking to whether dynamic/duck typing is good or bad here, just pointing out that the question is flawed.
[Disclaimer: I don't read Python, but I <i>think</i> the question here is "Which methods from this list does this object implement?" If I'm wrong please correct me.]<p>My gut check was this should take about eight lines, plus imports and the class boilerplate. Let's try:<p><a href="http://www.pastie.org/808727" rel="nofollow">http://www.pastie.org/808727</a><p>Yep, eight.<p>[Edit: It occurs to me the Python code might answer "Does this implement all specified methods?" That also takes eight lines in Java. I've appended the implementation above.]
I don't really care how many lines of Java this takes, if someone commits a garbage scenario like this I'm concerned with how many lines of comments they have explaining why they're doing it instead of solving the problem correctly.
The snippet is imprecise. it should be something like<p><pre><code> def hasmethod(obj, meth_name):
"""If it calls like a method it's a method."""
return callable(getattr(obj, meth_name)) if hasattr(obj, meth_name) else False</code></pre>
In CoffeeScript, it's a few lines less:<p><pre><code> has_methods: (obj, meth_names) ->
name for name in meth_names when obj[name] and obj[name].call</code></pre>