Through an online Dart course, I've found some values bracketed with "less than" and "greater than" marks such as "List< E >".
e.g.
List<int> fixedLengthList = new List(5);
I couldn't find a direct answer online, probably because that question was too basic. Could someone explain what those marks exactly indicate? Or any links if possible.
~ is currently only used for. ~/ Divide, returning an integer result. and ~/= integer division and assignment.
"!" is a new dart operator for conversion from a nullable to a non-nullable type. Read here and here about sound null safety. Use it only if you are absolutely sure that the value will never be null and do not confuse it with the conditional property access operator.
operator ~/ method Null safetyTruncating division operator. Performs truncating division of this number by other . Truncating division is division where a fractional result is converted to an integer by rounding towards zero. If both operands are ints, then other must not be zero.
Symbols in Dart are opaque, dynamic string name used in reflecting out metadata from a library. Simply put, symbols are a way to store the relationship between a human readable string and a string that is optimized to be used by computers.
This are generic type parameters. It allows specializations of classes.
List
is a list that can contain any value (if no type parameter is passed dynamic
is used by default).
List<int> is a list that only allows integer values and
null`.
You can add such Type parameters to your custom classes as well.
Usually single upper-case letters are used for type parameter names like T
, U
, K
but they can be other names like TKey
...
class MyClass<T> {
T value;
MyClass(this.value);
}
main() {
var mcInt = MyClass<int>(5);
var mcString = MyClass<String>('foo');
var mcStringError = MyClass<String>(5); // causes error because `5` is an invalid value when `T` is `String`
}
See also https://www.dartlang.org/guides/language/language-tour#generics
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With