mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
[dart/en] Updated example14 (#3881)
This commit is contained in:
parent
5c518f4a31
commit
ef5bdf1c52
@ -312,15 +312,15 @@ example14() {
|
|||||||
if (a) {
|
if (a) {
|
||||||
print("true, a is $a");
|
print("true, a is $a");
|
||||||
}
|
}
|
||||||
a = null;
|
a = false;
|
||||||
if (a) {
|
if (a) {
|
||||||
print("true, a is $a");
|
print("true, a is $a");
|
||||||
} else {
|
} else {
|
||||||
print("false, a is $a"); /// runs here
|
print("false, a is $a"); /// runs here
|
||||||
}
|
}
|
||||||
|
|
||||||
/// dynamic typed null can be convert to bool
|
/// dynamic typed null can not be convert to bool
|
||||||
var b;/// b is dynamic type
|
var b; /// b is dynamic type
|
||||||
b = "abc";
|
b = "abc";
|
||||||
try {
|
try {
|
||||||
if (b) {
|
if (b) {
|
||||||
@ -332,16 +332,16 @@ example14() {
|
|||||||
print("error, b is $b"); /// this could be run but got error
|
print("error, b is $b"); /// this could be run but got error
|
||||||
}
|
}
|
||||||
b = null;
|
b = null;
|
||||||
if (b) {
|
if (b) { /// Failed assertion: boolean expression must not be null)
|
||||||
print("true, b is $b");
|
print("true, b is $b");
|
||||||
} else {
|
} else {
|
||||||
print("false, b is $b"); /// runs here
|
print("false, b is $b");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// statically typed null can not be convert to bool
|
/// statically typed null can not be convert to bool
|
||||||
var c = "abc";
|
var c = "abc";
|
||||||
c = null;
|
c = null;
|
||||||
/// complie failed
|
/// compilation failed
|
||||||
/// if (c) {
|
/// if (c) {
|
||||||
/// print("true, c is $c");
|
/// print("true, c is $c");
|
||||||
/// } else {
|
/// } else {
|
||||||
|
Loading…
Reference in New Issue
Block a user