Answer the question
In order to leave comments, you need to log in
What are the pros and cons of being able to return null instead of a return type?
Example in Typescript:
function getStringsArray(): string[] {
return null // Type 'null' is not assignable to type 'string[]';
}
public static String[] getStringsArray() {
return null; // OK
}
Answer the question
In order to leave comments, you need to log in
Nullable references in Java are a billion-dollar mistake.
There are no advantages to this, it's just that at the time of development there was no thought that optional types should be added to the type system. Later, they tried to solve this with annotations like NotNull / Nullable, but they do not completely solve the problem, and besides, they are very verbose.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question