0

Edit: Sorry about posting here instead of the codegolf stackexchange, didn't heard of that before. Anyway thanks for the answers!

Okey, we all know the normal way to throw a NullPointerException in Java:

throw new NullPointerException(); // 33 characters

But I am searching for shorter (as in less characters) ways to do so. The shortest I could get was

((Void)null).toString(); // 24 characters

How can we produce a java.lang.NullPointerException with even less code and without imports?

There must be a way!

luckydonald
  • 5,976
  • 4
  • 38
  • 58

1 Answers1

4

For now shortest way I know is by

throw null;//11 characters 

You can find more info about it at Why can I throw null in Java?

Community
  • 1
  • 1
Pshemo
  • 122,468
  • 25
  • 185
  • 269