Miras Kairanov Miras Kairanov - 9 months ago 64
Dart Question

Dart strong mode: on casting implementation to abstract class implementation's are still visible and compiler is not throwing errors

My abstract class:

abstract class Animal {
void saySomething() {
debugPrint("I'm an animal");
}
}


My implementation class:

class Cow implements Animal {
int _mooCount = 0;
Cow();
Cow.withCount(this._mooCount);

Cow action({
String sound,
int setCount,
int removeCount,
bool flushCount
}) {
this._mooCount++;
if (setCount != null) {
this._mooCount = setCount;
}
if (sound != null) {
debugPrint(sound + ",count= " + _mooCount.toString());
} else {
debugPrint("Mooo");
}
return this;
}

void saySomething() {
debugPrint("Auuuuuuuuuuuuuuu");
}
}


How do i use it:

Animal myCow = new Cow();
myCow = myCow.action(setCount: 0).action(sound: "Moooooooo");


Intellij IDEA says:


The method 'action' isn't defined for the class 'Animal'


But everything compiles well in strong mode.

analysis_options.yaml
:

analyzer:
strong-mode: true


flutter output:

I/flutter ( 6325): Mooo
I/flutter ( 6325): Moooooooo,count= 1
I/flutter ( 6325): Auuuuuuuuuuuuuuu

Answer Source

As Vyacheslav Egorov said, strong mode has no influence on Dart VM at the moment.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download