Comment

Comment by jussij

This is one (of many) reasons I have a dislike for Java:

    String myString = null;
    if (myString.equals("foobar")) { /* ... */ }
    // This causes a NullPointerException in Java
Here is some equivalent C# code:

    using System;
    
    namespace SampleApplication
    {
        static class Program
        {
            static void Main(string[] args) {
                String myString = null;
    
                if (myString == "foobar") {
                    Console.WriteLine("???");
                }
                else {
                    Console.WriteLine("No good!!");
                }
            }
        }
    }
and sure enough it produces what I consider the correct logical output:

    No good!!
parent jussij 13 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton