the shortest code to throw a NullPointerException

If I were to throw a NullpointerException from within my code I normally would code something like this:

if(somethingIsNull) {
  throw new NullPointerException();
}

While reading the code examples on https://github.com/reactive-streams/reactive-streams-jvm I just saw this definitely shorter possibility which I did not know up to now:

if(somethingIsNull) {
  throw null;
}

Leave a Reply

Your email address will not be published. Required fields are marked *