Daniyar Changylov
Daniyar Changylov

Reputation: 568

Why need to extends Object?

I saw simple class which was look like:

class SomeClass extends Object{

  int a;
  int b;
  ...
  ...
}

Why this class was extended an Object class? As in documentation was written "Because Object is the root of the Dart class hierarchy, every other Dart class is a subclass of Object." in https://api.dartlang.org/stable/2.4.0/dart-core/Object-class.html.
What will happened if we will not extends Object? Or maybe it will be useful in some specific problems?

Upvotes: 1

Views: 550

Answers (1)

Rémi Rousselet
Rémi Rousselet

Reputation: 277677

All dart classes implicitly extend Object, even if not specified.

This can be verified using the following code:

class Foo {}

void main() {
  var foo = Foo();
  print(foo is Object); // true
}

Even null implements Object, which allows doing:

null.toString()
null.hashCode
null == something

Upvotes: 4

Related Questions