Lets say, I have a variable:var myObject : MyObject? = nullit should be cleared in some place : and should be definitely non-nullable in a place of usage. In Java I can do something like this:
Consider the usage of this expression:which effectively corresponds to this ternary expression:Is this usage of Optional.ofNullable with a method call a good practice? Or just extra verbose coding?
I have a method which compares two nullable ints and prints the result of the comparison to the console:
I have a very strange situation I don't understand. Below is the case simplified:I don't understand why one expression will net me true and another false. They seem identical.
This is a weird behaviour that I cannot make sense of. In my example I am having a class Sample<T> and in an implicit conversion operator from T to Sample<T>.
Consider the following code:When executed, it writes that Hashcode is 0, but fails with NullReferenceException in attempt to determine type of x. I know that methods called on nullable types are actually called on underlying values, so I expected program to fail during x.GetHashCode().