`

Favor static member classes over nonstatic

    博客分类:
  • Java
阅读更多

Here are 4 types of nested class.

  • static member class
  • none-static member class
  • anonymous class
  • local class

 

  • Anonymous Class & Local Class: Both are defined inside method or constructor of enclosing class.

If the class belongs inside a method/constructor, if you need to create instances from only one location and there is a preexisting type that characterizes the class, make it an anonymous class; else make it a local class.

  • Static member class & none-static: these classes defined in enclosing class.

If each instance of the member class needs a reference to its enclosing instance, make it nonstatic;

 

  • Static member class:

Can be instanced directlly, no need to instance the outer class first.

Eg. MyTest.StaticInnerClass sic = new MyTest.StaticInnerClass();

  • None-static member class:

Instance a none-static member class should create outer class first:
MyTest.InnerClass mi = new MyTest().new InnerClass();

  • Conclusion:

The static member class needn't instance the outer class, so it construct more efficient and less memory than none-static.

分享到:
评论

相关推荐

    Effective Java 3rd edition(Effective Java第三版英文原版)附第二版

    Item 24: Favor static member classes over nonstatic Item 25: Limit source files to a single top-level class 5 Generics Item 26: Don’t use raw types Item 27: Eliminate unchecked warnings Item 28: ...

    AdapterDelegates, 用于RecyclerView适配器的"Favor composition over inheritance".zip

    AdapterDelegates, 用于RecyclerView适配器的"Favor composition over inheritance" AdapterDelegates阅读这个项目的动机在我的博客文章。依赖项这里库在 Maven 中心可用:compile '...

    POLAR FAVOR用户使用说明书.pdf

    《Polar Favor用户使用说明书》提供了详尽的指南,帮助用户了解并充分利用Polar Favor心率监测设备。以下是对说明书内容的详细解析: 1. **Polar Favor的工作原理**(第5页):Polar Favor是一款智能心率监测器,...

    Java API for GitHub

    and those object references are used in favor of using string handle (such as GHUser.isMemberOf(GHOrganization) instead of GHUser.isMemberOf(String)) The library supports both github....

    TAO: Facebook's Distributed Data Store for the Social Graph

    Provide a data store with a graph abstraction (vertexes and edges), not keys/values Explicitly favor efficiency and availability over consistency

    Google C++ Style Guide(Google C++编程规范)高清PDF

    Scoping Namespaces Nested Classes Nonmember, Static Member, and Global Functions Local Variables Static and Global Variables Classes Doing Work in Constructors Default Constructors Explicit ...

    performer:FAVOR+注意力机制的简单Numpy实现,https

    描述中提到的“FAVOR+注意力机制”是Performer模型的一个变体,FAVOR代表“Fast Attention Via Orthogonal Random Features”,它利用正交随机特征来近似自注意力,从而实现在Numpy环境下的高效计算。这种方法的关键...

    ASP.NET 2.0 Beta Preview

    (WROX官方网站提供)What is this book about? ASP.NET 2 Beta Preview is timed ... Examples throughout the book do not favor one developer over another. Instead, every example is provided in both languages.

    【英文】德银报告:中国电子商务报告China E-commerce:A tale of two camps - and we favor the(72页).zip

    【英文】德银报告:中国电子商务报告China E-commerce:A tale of two camps - and we favor the(72页),资源名称:【英文】德银报告:中国电子商务报告China E-commerce:A tale of two camps - and we favor the...

    javasnmp源码-favor_repos:赞成_repos

    java snmp 源码 ~ C/C++ CppCon2017会议资料 A curated list of awesome C/C++ performance optimization resources. c++ lib,大杂烩,什么都有 c++ http lib c++ lib 嵌入的高速数据同步库 ...内存型HAT-trie

    Android代码-Android 上漂亮的 Dialog 效果

    > Favor composition over inheritance. LovelyDialog doesn't subclass any Dialog related classes, it is just a lightweight extensible wrapper for Dialog and manipulations with custom view. If you would ...

    A Small Favor-crx插件

    《A Small Favor-crx插件》是一款以英语为主要语言的冒险类游戏,它将玩家带入了一个遥远的外星世界,展开了一场紧张刺激的任务。在这个游戏中,玩家扮演的角色是一位神秘的刺客,接受了一项看似微不足道却至关重要...

    大学英语四级作文模板

    4. 作者立场:"As far as I am concerned, my favor goes to the first/second view.",明确个人立场。 5. 论证作者立场:"Admittedly, …but it doesn’t follow that…",承认对方观点的合理性,但提出自己的理由...

    effectice_java第二版 英文

    1. **条目1:始终考虑使用接口( Favor Interfaces over Abstract Classes)** 接口提供了一种多继承机制,使得类可以实现多个接口而不限于一个父类。这有助于保持代码的灵活性和可扩展性。 2. **条目2:考虑为...

    Android代码-一个容易使用android sharepreference的库

    Favor A easy way of using Android SharedPreferences. How to use this library Using Gradle compile 'com.cocosw:favor:0.2.0@aar' Using Maven com.cocosw favor 0.2.0 apklib API 1 Define a ...

    domeafavor-android:爱彼迎 - Android

    【标题】"domeafavor-android: 爱彼迎 - Android" 指的是一个开源项目,它可能是一个仿造或扩展Airbnb应用程序的Android平台实现。Airbnb是一款知名的在线住宿预订和旅游服务平台,而 "domeafavor-android" 可能是...

    flex----组件---数据验证类

    在IT行业中,尤其是在开发用户界面时,数据验证是至关重要的一个环节。Flex作为一个开源的、基于ActionScript的框架,主要用于创建富互联网应用程序(RIA)。它提供了丰富的组件库,其中包括用于数据验证的类,使得...

    高考名校最新模拟试题解析:介词[精选].doc

    6. "in favor of"表示“支持,赞成”,与句子中“大多数人赞成计划”相符,所以正确答案是"B. in favor of"。 7. "in terms of"表示“根据,就...而言”,在这句话中用于表示评价科学家和工程师的标准,故选择"D. ...

    Optimizing Federated Learning on Non-IID Data with Reinforcement

    针对这个问题,文章提出了一种名为FAVOR(Favor)的经验驱动的控制框架。FAVOR利用强化学习策略来优化非IID数据环境下的联邦学习过程。具体来说,它通过智能选择参与每轮联邦学习的客户端设备,以平衡非IID数据引入...

Global site tag (gtag.js) - Google Analytics