Why Android Studio Has This @nullable Thing?
Solution 1:
Viewcan be null because it is a reference type. But why an explicit@Nullableannotation?
In technical sense, yes, View is reference thus null is one of values. In the same sense, width and height arguments in one of overloads are of type int so technically you could pass 0, 2147483647 or -1 value as height, for example, but it probably wouldn't make any sense. The same way, passing null as a value, however syntactically valid, may or may not make sense. Some functions throw NullPointerException when passed a null value. @Nullable annotation means that null is acceptable value, and function will handle that:
Denotes that a parameter, field or method return value can be null.
When decorating a method call parameter, this denotes that the parameter can legitimately be null and the method will gracefully deal with it. Typically used on optional parameters.
When decorating a method, this denotes the method might legitimately return null.
This is a marker annotation and it has no specific attributes.
Post a Comment for "Why Android Studio Has This @nullable Thing?"