Monday, October 10, 2011

Google Dart

interface IMyClass {
  void dump();
}

class MyClass implements /* java style */ IMyClass {
  int x;

  MyClass(int x) {
    this.x = x;
  }

  void dump() {
    print('MyClass{$x}'); // php???
  }
}

class MagicException implements Exception {
  String message;

  MagicException(String message) {
    this.message = message;
  }
}

main() {
  List<IMyClass> mcs = new List<myclass>();
  for(int i = 0; i<5; ++i) mcs.add(new MyClass(i+1));

  func(IMyClass x) => x.dump();
  // or even this way:
  // var func = (IMyClass x) => x.dump(); // c#!!!

  for(IMyClass mc in mcs) {  
    func(mc);
  }

  print(mcs[0] is IMyClass);
  print(mcs[0] is MyClass);
  print(mcs[0] is !int);

  try {
    throw new MagicException('hai there');
  } catch(MagicException ex) {
    print(ex.message);
  } finally {
    print('finally');
  }
} 

They did it. I CAN WEB NOW!

No comments:

Post a Comment