why final is been used in --> public static final System out;
in the system class
why final is been used in --> public static final System out
Started by sharathm, Sep 02 2011 07:16 AM
4 replies to this topic
#1
Posted 02 September 2011 - 07:16 AM
|
|
|
#2
Posted 02 September 2011 - 09:19 AM
It's done like this so that you can't just simply change them. You must call setIn(), setOut(), etc, which can then validate your changes.
OBDMobile http://sites.google....te/obdiimobile/
#3
Posted 02 September 2011 - 10:24 AM
Actually final won't let you change it even through the setter method. It must be going around the restriction somehow. I was looking around in the Java source and managed to track the code until:
and then:
i read that native keyword indicates that non-java code is being run from the method. No idea where it goes further....
public static void setOut(PrintStream out) {
checkIO();
setOut0(out);
}
and then:
private static native void setOut0(PrintStream out);
i read that native keyword indicates that non-java code is being run from the method. No idea where it goes further....
#4
Posted 02 September 2011 - 12:43 PM
I suppose the final keyword is only checked at compile-time so avoidable at runtime using reflection or anything.
#5
Posted 02 September 2011 - 05:03 PM
One of the nice things about Java is that you don't have to know why it works, just that it does. :)
[JavaSpecialists 096] - Java 5 - "final" is not final anymore - A nice read.
[JavaSpecialists 096] - Java 5 - "final" is not final anymore - A nice read.
OBDMobile http://sites.google....te/obdiimobile/
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









