if (obj is String) {
print("string");
} else if (obj is List) {
print("list");
} else {
print("object");
}
when (obj) {
is String -> print("string");
is List -> print("list");
else -> print("object");
}
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
Pattern matching was asked several times in the past in feature requests (I asked it too) and it was just refused.
Hopefully someone asks it again formally and they might consider it.
It's not only about fallthrough, switch only allows to compare integer, string, or compile-time constants that don't have custom == implementation.
What would be the purpose of "when" other than replacing if-else-chains ?
class Box {final num value;Box(this.value);}main() {Box boxed = new Box(12.34);if (boxed.value is int) {print(boxed.value.isEven);}}
if (boxed.value is int) {print((boxed.value as int).isEven);}