Java-Final

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java-Final相关的知识,希望对你有一定的参考价值。

FinalData

1.two kinds of final data:compile_time data(primitives with keyword final) and run_time data

2.final+static fields has only one storage that can‘t be changed

3.final reference----refer is constant not the value of the refer (arrays included)

(in c++,the value of the const refer can‘t be changed)

         final primitives----constant 

4.final != you know the value when running  ==>  static and non-static

5.use "public static final" most  (capitals+underscores)

BlankFinal

  1. guaranteed initialized before using

  2. flexibility

  3. initialized in constructor or definition field

FinalArguments

  1. can‘t change the value of the arguments

  2. especially, when argument is a refer, can‘t change what it refers to, but can change the value of the pointed object

FinalMethod

  1. two reasons for final method:first,prevent overriding,  for design reason, may what to retain the method from changed (by inheritance);secondly, for time_saving ,final method is inline method,which saves time.

  2. now ,optimizing a method using final is not encouraged

Final&Private

  1. private method is declared final implicityly

  2. "overriding" happens when base-class method is private,you create a public/protected method that has the same name

FinalClass

  1. final class can‘t be inherited

Caution


本文出自 “Maugham的进阶之旅” 博客,请务必保留此出处http://maugham.blog.51cto.com/13056751/1980185

以上是关于Java-Final的主要内容,如果未能解决你的问题,请参考以下文章