Reputation: 568
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
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