Thomas (boggyb) wrote,
Thomas
boggyb

  • Mood:
  • Music:

Java pet peeve #3

Pet peeve #3 about Java: the lack of destructors.

What I would like to happen:
    public Predator()
    {
        System.out.println("Say hello to " + this);
    }
    
    public ~Predator()
    {
        System.out.println("Someone killed " + this);
    }


What I have to do in Java:
    public Predator()
    {
        System.out.println("Say hello to " + this);
    }
    
    public void finalize()
    {
        System.out.println("Someone killed " + this);
    }

and if I'm wearing my lucky rabbit's foot, the moon is blue, and a black cat is following me, then finalize() might just get called when the Predator gets killed. In fact I'm lucky (it seems) if finalize() gets called at all. Hmm. So much for my bright idea for debugging.


In case you're wondering, pet peeves #1 and #2 in Java are the inability to switch() on a String, and the lack of enums in any sane form.
Subscribe
  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 6 comments