Monday, March 29, 2010

Null Pointer Exception

This is why I don't program in Java:
import java.util.ArrayList;

class Program
{
class Person
{
public Person partner;
}

class Prostitute extends Person { }
class Eunich extends Person { }

private Prostitute prostitute;
private Eunich eunich;

public static void main(String[] args) {
Program p = new Program();
p.run();
}

public void run() {
eunich.partner = prostitute;
}
}

> Exception in thread "main" java.lang.NullPointerException

But if you do, you should check out the nifty online JXXX Compiler Service.

4 comments:

  1. So you don't program in Java because it throws a NullPointerException, correctly, when trying to use a null object reference?

    ReplyDelete
  2. Perhaps I should have written "this is why I'm not *allowed* to write Java." I can't resist the temptation writing joke code like that (eunich couldn't meet up with the prostitute because of a null pointer) to amuse myself, especially when there's the misconception that there are not pointers in Java. Sophomoric humor? Sure. But we all have our downfalls.

    ReplyDelete
  3. Tim thinks installing the jdk is like giving your system a lobotomy =D

    ReplyDelete
  4. Yeah I actually totally ignored the whole "concept" you had in there and just looked at the code as code ;)

    ReplyDelete