Overriding core functions in Dart

An interesting question came up on the Dart mailing list today, asking how to essentially overload a core function, avoiding a name collision.

For example, how to handle this?

class Printer {
                       // print() comes from dart:core
  print(String msg) => print(msg);
}

The dart:core top level function print() is available and defined, however what do you do if you want to name a method print() ?

Thanks to Sam McCall, there are a few options:


Function consolePrint = print; 
class Printer { 
  print(m) => consolePrint(m); 


and

consolePrint(m) => print(m); 
class Printer { 
  print(m) => consolePrint(m); 



Thanks for the question and answer about Dart!

Popular posts from this blog

The 29 Healthiest Foods on the Planet

Lists and arrays in Dart

Converting Array to List in Scala