- Making a class final is double edged sword. Some JAVA programmer argue that Final class severely limits client ability to inherit and extends. While some JAVA programmer are in opinion that Final class which is IMMUTABLE are the best way to design ROBUST system. It's trade-off, James's Gosling suggest that making a class final in java is for Security reason e.g String is justified
- Only Final variable is accessible inside anonymous class in JAVA.
- FINAL is different than FINALLY keyword which is used on Exception handling in JAVA.
- Final should not be confused with FINALIZE method which is declared in Object Class and called before an Object is collected by JVM.
- All variable declared inside java interface are implicitly Final.
- FINAL and ABSTRACT are two opposite keyword and Final Class can not be abstract in JAVA.
- Making a collection reference variable Final means only reference can not be changed but you can add,remove or change object inside Collection. For e.g.
- private final List loans=new ArrayList();
- list.add("Home Loan"); //valid
- list.add("Personal Loan"); //valid
- loans=new Vector(); // Not Valid
8. Final Keyword improves performance. Not JVM can cache Final variable but also application can cache frequently use Final Variable.
9. Final variables are safe to share in MULTI THREADED Environment without additional synchronization overhead.
10. Final keyword allows JVM to optimized.
If you have any doubt or information on this. Please comment!
If you have any doubt or information on this. Please comment!
No comments:
Post a Comment