Can final mutable variables be manipulated... ?
Can final mutable variables be manipulated. ?I found written somewhere that final variables can still be manipukated unless its marked immutable...Can any one explain on this with some example if possible.
[226 byte] By [
Shebua] at [2007-11-27 9:47:17]

There are probably several ways to do it. The System.out attribute is final but is changed/altered using JNI.KajMessage was edited by: kajbj
kajbja at 2007-7-12 23:59:23 >

Final references can't be changed, but that doesn't affect the object that the reference points to. If the object is mutable, then it's state can still be changed, even if it's reference be a final reference.
There's no way to "mark" a class or object as immutable, it's made that way by design. Usually by setting all members in the constructor and providing no way to change the data after construction.
> Can final mutable variables be manipulated. ?
Mutable/immutable applies to objects, not variables. There is no way to mark something immutable in Java.
The value of a final variable cannot be changed. The contents of an object pointed to by a final variable can be changed, if that object's member variables are not final and the class provides a means by which to change them.
jverda at 2007-7-12 23:59:23 >

> The value of a final variable cannot be changed. It can if you use JNI. The out attribute in the System class is declared as:public final static PrintStream out;and it's changed using JNI (by the method private static native void setOut0(PrintStream
kajbja at 2007-7-12 23:59:23 >

Yeah, I know. I was trying to clear up two basic concepts for the OP. Given the question he's asking, I don't think he's ready to start with that kind of voodoo yet. :-)
jverda at 2007-7-12 23:59:23 >

What u mean by OP...? n what basic concepts.. can u give some hints...?
Shebua at 2007-7-12 23:59:23 >

> What u mean by OP...? n what basic concepts.. can u> give some hints...?OP means Original Poster, in this case, you. The concepts were the difference between an object and it's reference, and how mutability/immutability applies to objects.
> Yeah, I know. I was trying to clear up two basic
> concepts for the OP. Given the question he's asking,
> I don't think he's ready to start with that kind of
> voodoo yet. :-)
Why not? I'm a consultant so I want people to try to run before they know how to walk :)
kajbja at 2007-7-12 23:59:23 >

> > Yeah, I know. I was trying to clear up two basic
> > concepts for the OP. Given the question he's
> asking,
> > I don't think he's ready to start with that kind
> of
> > voodoo yet. :-)
>
> Why not? I'm a consultant
That explains the desire to find a complex solution to a simple problem :)
> That explains the desire to find a complex solution> to a simple problem :)Exactly ;)
kajbja at 2007-7-12 23:59:23 >

is this answer to my query ...?
Shebua at 2007-7-12 23:59:23 >

> is this answer to my query ...?We've given you several answers, what don't you understand?
> is this answer to my query ...?Yes, your question has been answered.
kajbja at 2007-7-12 23:59:23 >
