Is null check needed before instanceof in Java?
Hello everyone! I'm a beginner Java developer, and I have a question about the instanceof operator. In code, I often see this construct:\n\n```java\nif (obj != null && obj instanceof String) {\n // do something\n}\n```\n\nThis double check confuses me. If obj is null, then instanceof will still return false anyway, because null is not an instance of any class. Does this mean the null check is redundant? Or are there pitfalls?\n\nI tried writing a simple test:\n\n```java\nObject obj = null;\nSystem.out.println(obj instanceof String); // prints false\n```\n\nIndeed, without the null check the code works and doesn't throw a NullPointerException. But then why do many developers still write `obj != null && obj instanceof ...`? Is it just a habit or is there a reason?