3 ms·
The null check operator is much more concise than my pre-c# 6 solution. Moreover you can apply both my solution and the null check operator to any type, while f
by tigershark 10y ago
The null check operator is much more concise than my pre-c# 6 solution.
Moreover you can apply both my solution and the null check operator to any type, while for Java you have to specify that a field is optional (increasing the verbosity and moving the responsibility to who write the class) and you can't do it for types that you don't own.
So for these types the only way is to create a wrapper type just to add the optional fields, and this brings the amount of boilerplate code through the roof.
So, just to sum it up, contrary to what you say the c# solution works out of the box, is much shorter than the Java alternative and works for every type.
Honestly I can't really see why Java solution is superior for you.