3 ms·
I believe the question is asking 'if you have an object of unknown type, how do you introspect it to find out if it supports a method with name meth_name'. the
by brehaut 17y ago
I believe the question is asking 'if you have an object of unknown type, how do you introspect it to find out if it supports a method with name meth_name'. the test for callability is to determine of the objects member is callable, not if the object itself is callable.
Java's reflection system exists to answer this question. I'm not a Java guru though, so i couldnt forumlate the equivalent code
- jerf 17y agoIt is true that my answer elides over some things, but the underlying point is that there isn't a real comparison available between languages because in Java you should pretty much never need this. Yes, technically you could work yourself into a position where you might need that question answered and have to go through the reflection, but that is truly a last resort, whereas in Python it's sort of the first. (I say "sort of" because even in Python this is a weird thing; the traditional answer to the question "can I call this as a function" is to simply try it and catch the exception if it fails.)
- brehaut 17y agowell of course. Its a last resort in python too. while it's much easier to do in python, its far from idiomatic. It's getting into 'too much magic' territory.