You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been reading the comments about if-variables.
What if we introduced a "fix" keyword, so that we could do ...
classCoffee {
String? temperature;
voidheat() { temperature ='hot'; }
voidchill() { temperature ='iced'; }
voidcheckTemp() {
fix temperature;
if (temperature !=null) {
print('Ready to serve '+ temperature +'!');
} else {
temperature ='UNKNOWN';
}
// If we want the unfixed value we can just refer to it via this.temperature
}
Stringserve() => temperature!+' coffee';
}
The code above would be equal to ...
classCoffee {
String? temperature;
voidheat() { temperature ='hot'; }
voidchill() { temperature ='iced'; }
voidcheckTemp() {
var fixedTemperature = temperature;
if (fixedTemperature !=null) {
print('Ready to serve '+ fixedTemperature +'!');
} else {
fixedTemperature ='UNKNOWN';
temperature ='UNKNOWN';
}
}
Stringserve() => temperature!+' coffee';
}
Fixing a field is like creating a local copy at a fixed point in time. That copy persists until the end of the scope.
Writing to a fixed field is like updating a local copy in sync with the original field.
The unfixed field can always be fetched via this.field.
A fixed field can be refixed to refresh the fixed value.
Just throwing it out there :)
The text was updated successfully, but these errors were encountered:
I've been reading the comments about if-variables.
What if we introduced a "fix" keyword, so that we could do ...
The code above would be equal to ...
Just throwing it out there :)
The text was updated successfully, but these errors were encountered: