O'Reilly logo

Dart: Scalable Application Development by Ivo Balbaert, Sergey Akopkokhyants, Davy Mitchell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using noSuchMethod

When a method is called on an object, and this method does not exist in its class, or any of its superclasses in the inheritance tree, then noSuchMethod() from Object is called. The default behavior of noSuchMethod is to throw a NoSuchMethodError, method not found: 'methodname'. However, Dart can do more; as in some other dynamic languages, every class can implement noSuchMethod to make its behavior more adaptive and flexible. This is because of the fact that Dart is dynamically typed, so it is possible to call a method that does not exist in a dynamic variable. In Java, you get a compile time error for this. In Dart too, an error is thrown but at runtime. By using noSuchMethod(), we can circumvent this and put it to our use. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required