Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

dart.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.

Learn more

Dart 3.11 is live!Learn more

Callable objects

Learn how to create and use callable objects in Dart.

To allow an instance of your Dart class to be called like a function, implement thecall() method.

Thecall() method allows an instance of any class that defines it to emulate a function. This method supports the same functionality as normalfunctions such as parameters and return types.

In the following example, theWannabeFunction class defines acall() function that takes three strings and concatenates them, separating each with a space, and appending an exclamation. ClickRun to execute the code.

class WannabeFunction {  String call(String a, String b, String c) => '$a $b $c!';}var wf = WannabeFunction();var out = wf('Hi', 'there,', 'gang');void main() => print(out);
Was this page's content helpful?

Unless stated otherwise, the documentation on this site reflects Dart 3.11.0. Page last updated on 2025-10-18.View source orreport an issue.


[8]ページ先頭

©2009-2026 Movatter.jp