Callable object
A callable object, in computer programming, is any object that can be called like a function.
≈ 3 min read
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
A callable object, in computer programming, is any object that can be called like a function.
In different languages
edit edit sourceIn C++
edit edit source- pointer to function;
- pointer to member function;
- functor;
- lambda expression.
std::functionis a template class that can hold any callable object that matches its signature.
In C++, any class that overloads the function call operator operator() may be called using function-call syntax.
In C#
edit edit sourceIn PHP
edit edit sourcePHP 5.3+ has first-class functions that can be used e.g. as parameter to the usort() function:
It is also possible in PHP 5.3+ to make objects invokable by adding a magic __invoke() method to their class:[1]
In Python
edit edit sourceIn Python, any object with a __call__() method (as well as all functions, classes, and methods) can be called using function-call syntax. The built-in callable function can approximately detect whether a given object is callable or not.[2][3]
A collections.abc.Callable type annotation can be used to declare that a given variable must be callable. A Callable[P, R], where P is a list of types and R is a type, can be called with values matching P as arguments and returns a value of type R. Other values for P, such as a ParamSpec or ..., denote more flexible cases.[4]
In Dart
edit edit source
Callable objects are defined in Dart using the call() method.
In Swift
edit edit sourceIn Swift, callable objects are defined using callAsFunction.[6]
References
edit edit source- ^ PHP Documentation on Magic Methods Wikipedia revision 1373121774, retrieved 2026-11-18
- ^ "Glossary § callable". Python 3.14.7 documentation. Python Software Foundation. 2026-09-01. Retrieved 2026-09-01.
{{cite web}}: CS1 maint: url-status (link) Wikipedia revision 1373121774, retrieved 2026-11-18 - ^ "Built-in Functions § callable". Python 3.14.7 documentation. Python Software Foundation. 2026-09-01. Retrieved 2026-09-01.
{{cite web}}: CS1 maint: url-status (link) Wikipedia revision 1373121774, retrieved 2026-11-18 - ^ "typing — Support for type hints § Annotating callable objects". Python 3.14.7 documentation. Python Software Foundation. 2026-09-01. Retrieved 2026-09-01. Wikipedia revision 1373121774, retrieved 2026-11-18
- ^ "A Tour of the Dart Language". www.dartlang.org. Retrieved 2019-03-25. Wikipedia revision 1373121774, retrieved 2026-11-18
- ^ "Declarations — The Swift Programming Language (Swift 5.6)". docs.swift.org. Retrieved 2022-02-28. Wikipedia revision 1373121774, retrieved 2026-11-18
External links
edit edit sourceText derived from https://en.wikipedia.org/w/index.php?oldid=1373121774 under CC BY-SA 4.0; modifications have been made.