1. A nested class should exist only to serve its enclosing class. If a nested class would be useful in some other context, then it should be a top-level class.
2. There are four kinds of nested classes: static member classes, nonstatic member classes, anonymous classes, and local classes.
3. A static member class is best thought of as an ordinary class that happens to be declared inside another class and has access to all of the enclosing class’s members. It’s a static member of its enclosing class and obeys the same accessibility rules as other static members. One common use of a static member class is as a public helper class, useful only in conjunction with its outer class. (i.e. The Operation enum should be a public static member class of the Calculator class.)
4. Within instance methods of a nonstatic member class, you can invoke methods on the enclosing instance or obtain a reference to the enclosing instance using the qualified this construct. If an instance of a nested class can exist in isolation from an instance of its enclosing class, then the nested class must be a static member class.
5. One common use of a nonstatic member class is to define an Adapter that allows an instance of the outer class to be viewed as an instance of some unrelated class. For example, implementations of the Map interface typically use nonstatic member classes to implement their collection views, which are returned by Map’s keySet, entrySet, and values methods. Similarly, implementations of the collection interfaces, such as Set and List, typically use nonstatic member classes to implement their iterators.
6. If you declare a member class that does not require access to an enclosing instance, always put the static modifier in its declaration. If you omit this modifier, each instance will have an extraneous reference to its enclosing instance. Storing this reference costs time and space, and can result in the enclosing instance being retained when it would otherwise be eligible for garbage collection.
7. A common use of private static member classes is to represent components of the object represented by their enclosing class. (i.e. Map.Entry)
8. Anonymous classes have enclosing instances if and only if they occur in a nonstatic context. But even if they occur in a static context, they cannot have any static members. One common use of anonymous classes is to create function objects (Item 21) on the fly.
9. Local classes have enclosing instances only if they are defined in a nonstatic context, and they cannot contain static members.
相关推荐
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: ...
46 PROC. OF THE 12th PYTHON IN SCIENCE CONF. (SCIPY 2013)Pythran: Enabling Static Optimization of Scientific Python ProgramsSerge Guelton∗†, Pierrick Brunet‡, Alan Raynaud‡, ...them in favor of powe
表演者 + 注意力机制的简单 Numpy 实现在Rethinking Attention with Performers ,以及在我的文章中复制实验的代码: 。
AdapterDelegates, 用于RecyclerView适配器的"Favor composition over inheritance" AdapterDelegates阅读这个项目的动机在我的博客文章。依赖项这里库在 Maven 中心可用:compile '...
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 ...
flutter_apprizee 一个新的Flutter应用程序。 入门 该项目是Flutter应用程序的起点。 如果这是您的第一个Flutter项目,那么有一些资源可以帮助您入门: 要获得Flutter入门方面的帮助,请查看我们的,其中提供了...
Scoping Namespaces Nested Classes Nonmember, Static Member, and Global Functions Local Variables Static and Global Variables Classes Doing Work in Constructors Default Constructors Explicit ...
【英文】德银报告:中国电子商务报告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...
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....
Provide a data store with a graph abstraction (vertexes and edges), not keys/values Explicitly favor efficiency and availability over consistency
java snmp 源码 ~ C/C++ CppCon2017会议资料 A curated list of awesome C/C++ performance optimization resources. c++ lib,大杂烩,什么都有 c++ http lib c++ lib 嵌入的高速数据同步库 ...内存型HAT-trie
domeafavor-android 爱彼迎 - Android
> 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 ...
(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.
Por favor ingrese una dirección IP o 'salir' 1.2.3.4 Por favor ingrese una dirección IP o 'salir' 1.2.3.3 Por favor ingrese una dirección IP o 'salir' 1.2.3.1 Por favor ingrese una dirección IP o ...
POLAR品牌说明书
… has become a hot topic among people ...As far as I am concerned, my favor goes to the first/second view. Admittedly, …but it doesn’t follow that… Only if … can we…, just as the saying goes…
【英文】德银报告:中国电子商务报告China E-commerce:A tale of two camps - and we favor the
In general, Ruby programmers tend to favor the the command line for running their code, and they tend to use text editors rather than IDEs. * Ruby runs on Windows, Linux, and Macs.
NULL 博文链接:https://z466459262.iteye.com/blog/901207