Re: [Hampshire] Happy Happy Joy Joy

Top Page

Reply to this message
Author: Samuel Penn
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] Happy Happy Joy Joy
On Sunday 23 September 2007 10:57:01 Graham wrote:
> On Sun, 2007-09-23 at 10:27 +0100, Samuel Penn wrote:
> > On Sunday 23 September 2007 09:52:35 Graham wrote:
> > [...snip stuff about Java and C++...]
> >
> > > The lack of an object lifecycle and the lack of constness are just two
> > > of the things that continue to frustrate me with Java.
> >
> > What do you mean by these? I think I know about you mean, but
> > don't see how they're lacking in Java. Unless you mean you don't
> > like garbage collectors. The final keyword gives you constants.
>
> There's no object lifecycle because there's no guarantee when a
> destructor will be called, if ever. Unlike C++, the scope doesn't
> define when an objects destructor is called.


It's called when it's garbage collected, but no you don't know
when it will be garbage collected. Even a call to System.gc() is
only a hint that maybe now is a good time to perform garbage
collection, but isn't a guarantee that it will actually do it.

I have actually run into a problem recently when trying to delete
files, since file handles weren't being closed until something
was garbage collected, and under Windows an open file handle prevents
you deleting the file. First time it's been an issue in ~10 years,
and there were ways around it.

Generally though, you don't need destructors in Java (I've only
seen them used once, and they ended up being removed because
they caused a bug by closing something that was still being used
rather than simply letting the GC 'do the right thing').

> As for final, it is not the same as const. It only indicates that a
> variable won't be reassigned, but you can still change its state.


Okay, I see. Can't say I've ever needed to do this, and don't
see it as being much of an issue. If you're writing X yourself,
you'd make the private variable final, or remove the setter
(it really shouldn't have a setter in the first place, if i is to
be final). Or wrap it in another class which has no setter. How
often do you really need to do this?

-- 
Be seeing you,                         http://www.glendale.org.uk
Sam.                        Mail/IM (Jabber): sam@???