3 ms·
Java is a language where nullable types aren't truthy/falsy. The following code won't compile: String foo = null; if (foo) { // error: incompatible types:
by kibwen 9y ago
Java is a language where nullable types aren't truthy/falsy. The following code won't compile:
String foo = null;
if (foo) { // error: incompatible types: String cannot be converted to boolean
System.out.println("was true");
} else {
System.out.println("was false");
}
If one changes `if (foo)` to `if (foo != null)`, then the code will compile.
- smitherfield 9y agoRight. I haven't written any Java in a while so it slipped my mind.
- pjmlp 9y agoSame applies to any language derived from Algol linage.