Hello.
I have the following singleton:
public class Singleton {
private static final Singleton singleton = new Singleton();
private ArrayList<String> list = new ArrayList<String>();
private Singleton() {
}
public static Singleton getInstance() {
return singleton;
}
// ..... and some public methods to access "list";
}
.... and i have the following class:
public class Usage {
private final Singleton singletonInstance =
Singleton.getInstance();
}
My question is: it is ok that in Usage class the singletonInstance is
declared final? can i still add/delete from the list declared in the
Singleton? Why?
Thank you in advance
> Hello.
>
[quoted text clipped - 29 lines]
> declared final? can i still add/delete from the list declared in the
> Singleton? Why?
The final applies to the reference to the Singleton instance, not to its
contents. It simply prevents you from changing to a different Singleton
instance.
Matt Humphrey matth@iviz.com http://www.iviz.com/
horvath.alexandru@gmail.com - 02 Apr 2006 03:49 GMT
I understand now :) .
I'm new to Java so i am sorry if my question was a little silly.
Thank you for your quick response.
> > Hello.
> >
[quoted text clipped - 35 lines]
>
> Matt Humphrey matth@iviz.com http://www.iviz.com/
Jinkx - 02 Apr 2006 07:40 GMT
It was not at all silly., it was a very good question . Even i had
little idea about that...
On 1 Apr 2006 18:19:38 -0800, "horvath.alexandru@gmail.com"
<horvath.alexandru@gmail.com> wrote, quoted or indirectly quoted
someone who said :
> private final Singleton singletonInstance =
>Singleton.getInstance();
[quoted text clipped - 4 lines]
>declared final? can i still add/delete from the list declared in the
>Singleton? Why?
Why would final not be ok? You don't change the value anywhere do you?
Final is not C++ const. It simply means the reference to the object is
frozen. It says nothing about changing the value of fields in the
object. It says there is one object for all time.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.