Is Final really Final?

Java has a keyword final and C++ has a keyword const. They are similar, but don't fall into the trap of thinking they are identical. Declaring a variable final will prevent the value of that variable from being changed after initialization. However, if that variable is a reference to an object, it will not necessarily prevent the various fields in that object from being changed. e.g. This also applies to parameters declared final.

final Table finalTable = new Table(7 );
Table otherTable = new Table(7 );
tb = otherTable; // generates a compiler error
finalTable.setSize( 10 ); //ok
finalTable.color = 6;     //ok


FAQ Home

 
Printer friendly version of the FAQ-JAVA-Is-Final-Really-Final page


Sponsored links

Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Check Out IT Certification Preparation Materials
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
SFTP components for .NET
Add complete SSH and SFTP support to your .NET framework application
Virtual File System SDK
Create your own file systems in Windows and .NET applications
PureCM Software Configuration Management
Version control and integrated issue tracking - powerful and easy to use. Get your FREE trial now!

Advertisement



Free Magazine

Free Magazines
eWeek The essential technology information source for builders of e-business.... subscribe now

Newsletter | Submit Content | About | Advertising | Awards | Contact Us | Link to us |
© 1996-2008 Community Networks Ltd All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Synchron Data - .NET development.