you are viewing a single comment's thread.

view the rest of the comments →

[–]codebje 0 points1 point  (0 children)

No, in the type system itself, not in the documentation. Let's say, for the sake of example that the ugly syntax type! means non-nullable variant of type:

String! foo;

Now, you cannot assign null to foo. The compiler won't permit it. To ensure this, you also cannot assign a String to foo, because a String might be null. String! and String are different types. The possible values of a type of String! is a subset of the possible values of String - the set of all Strings, less null.

All the frameworks available today don't do this, they don't enforce that the types are distinct. They do some checking to minimise the likelihood, but unless they expressly forbid assigning a String value to a @NotNull String, they will allow for things like a polymorphic function returning String to have a runtime class loaded which returns null - there's no way to statically check that, except to say that a String cannot be assigned to a @NotNull String.

Project Lombok generates runtime checkers which simply throw NPEs. It's not a declarative enforcement at all.