?

Log in

No account? Create an account
'Twas brillig, and the slithy toves did gyre and gimble in the wabe [entries|archive|friends|userinfo]
Thomas

[ website | Beware the Jabberwock... ]
[ deviantArt | the-boggyb ]
[ FanFiction | Torkell ]
[ Tumblr | torkellr ]

Links
[Random links| BBC news | Vulture Central | Slashdot | Dangerous Prototypes | LWN | Raspberry Pi]
[Fellow blogs| a Half Empty Glass | the Broken Cube | The Music Jungle | Please remove your feet | A letter from home]
[Other haunts| Un4seen Developments | Jazz 2 Online | EmuTalk.net | Feng's shui]

Java pet peeve #3 [Saturday 26th February 2005 at 9:56 pm]
Thomas

boggyb
[Feeling |busybusy]
[Playing |Generic background ~ Team17/Worms World Party (set on loop)]

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.
Link | Previous Entry | Share | Flag | Next Entry[ 6 pennies | Penny for your thoughts? ]

Comments:
[User Picture]From: ralesk
Sunday 27th February 2005 at 3:06 pm (UTC)

Needing half the time a pointer and half the time a true variable is my problem really :P

(Reply) (Parent) (Thread)
[User Picture]From: olego
Sunday 27th February 2005 at 4:44 pm (UTC)
Well, what I do is this:

If I have a main function that calls other functions, main has the object and all other functions have the pointer.

If I have no functional main (i.e. a WinMain, with a message loop), then make a global pointer, malloc it before DialogBox(), and free it right after.

:-)
(Reply) (Parent) (Thread)