Iodine extends the language with nullability annotations, matching the syntax we also use for C# and Mercury. Reference types – which are nullable by default – can be marked as not nullable by suffixing the type name with an exclamation point (
!), and value types can be marked as nullable with a question mark (
This can make for more robust code, as variables, fields, properties or parameters declared as such can be relied on to not be
null. In many cases, the compiler can even emit compile-time warnings or errors, for example when passing a literal
Nothing to a non-nullable parameter.
For consistency, the
! operator is alos allowed on value types, where it will be ignored, simliar to how the
? is allowed on referene types (are nullable by default) and is ignored there.
Int32 i1; // non-nullable by default, 0 Button b1; // nullable by default, null Int32! i1; // non-nullable by default, 0, same as above Button? b1; // nullable by default, null, same as above Int32? i2; // nullable, null Button! b2 = new Button(); // not nullable, thus needs initialization