aspose file tools*
The moose likes Beginning Java and the fly likes about final? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about final?" Watch "about final?" New topic
Author

about final?

Yu-Jie Jang
Greenhorn

Joined: Dec 28, 2003
Posts: 3
1.Difference final used primtive and object?
2.When I used , what should be note ?
3.If I exchange some access , somethings should noted (like value or reference ... )?
Wesley Tai
Greenhorn

Joined: Sep 30, 2003
Posts: 6
Hi:
if use the key word "final",something should be noted.
"final" can be used in the three part:
1.if use before a class
that means the class don't have the inheritor.
for example:final class ABC
2.if use before a variable
that means the value of the variable can't be change.
for example:final int x=5;
3.if use before a method
that means the method can't be override
for example:final void bprt(){...}
In addition,use "final static"
for example:final static int y=5;
then y is a constant.
That's all.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
1.Difference final used primtive and object?
Let's momentarily ignore the delayed initialization pitfall that you can fall into with any instance or class variables, not just final ones.
If the keyword final is used to modify a variable, it's telling the compiler and anybody else that cares, that the value of that variable cannot be changed, once it is assigned. In the case of primitive variables, a final variable cannot have its primitive value changed. In the case of object references, a final reference always refers to the same object, and cannot be changed to refer to a different object.
Now, for a good explanation of how a final variable might actually have more than one value, take a look at Java Code Talk, Part 4 by Joshua Bloch and Neal Gafter.
2.When I used , what should be note ?
I'm not sure what you're asking.
3.If I exchange some access , somethings should noted (like value or reference ... )?
Again, I'm not sure what you're asking.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: about final?