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

  • Misty creek and eerie fog

    So today started grey, and as the afternoon went on Fareham creek became very misty... The skies cleared for a brief moment as the sun…

  • Pokémon Go

    I've been playing a lot of Pokémon Go while out on walks, and experimenting with the AR photo mode... Cross-posted to deviantArt Cross-posted…

  • Random photo

    Just a random photo taken in the local sensory garden, while out and about today... There was just something that caught my eye about the…

  • 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