小心別讓日子把你給混了

          光榮在于平淡...艱巨在于漫長(zhǎng)...
          posts - 26, comments - 7, trackbacks - 0, articles - 1
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          Something About Final

          Posted on 2007-06-26 09:15 60 閱讀(264) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): JAVA筆記

          Final

          when using final object references rather than primitives the meaning gets a bit confusing.With a primitive, final makes the value a constant, but with an object refercence,final makes the reference a constant.

          1. blank finals
          java allows the creation of blank finals, which are fields that are declared as final but are not given an initialization value. in all cases, the blank final must be initialized before it is used, and the compiler ensures this.However, blank finals provied much more flexibility in the use of the final keyword since.the blank final should be initialized in the constructor.

          2. Final methods
             Tow reasons for final methods. The first is to put a "lock" on the method to prevent any inheriting class from changing its meaning. This is done for design reasons when you want to make sure that a method's behavior is retained during inheritance and cannot be overidden.
             The second reason for final methods is efficiency. If u make a method final,you are allowing the compiler to turn any calls to that method into inline calls
             However, it's better to not trust that the compiler is able to do this and make a method final only if it's quite small or if you want to explicitly prevent overriding.

          3.Final class
            Defining the class as final simply prevents inheritance nothing more.
            

          主站蜘蛛池模板: 许昌县| 鄂托克前旗| 深州市| 苏州市| 堆龙德庆县| 从化市| 房产| 广灵县| 盘山县| 沙河市| 本溪市| 东丽区| 祥云县| 柘城县| 应城市| 巴彦淖尔市| 晋宁县| 赤壁市| 门源| 淮阳县| 佛教| 泗阳县| 洪江市| 土默特左旗| 平昌县| 灵武市| 七台河市| 永州市| 榆林市| 华亭县| 庆城县| 清河县| 邢台县| 贡山| 昌吉市| 广宗县| 青河县| 琼海市| 民权县| 林西县| 大渡口区|