本人在看Android文档的时候发现有个Java语法还挺有意思的,就是Java Nested class,查看了sun的文档,原来是类里面的嵌套类。http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html


本人介绍一篇文章给大家看看:http://www.cn-java.com/www1/bbs/redirect.php?tid=13595&goto=lastpost&sid=D7zYoM


为什么要使用 Nested class???官方的解释如下

1、类在逻辑山的分组

2、增加封装性

3、代码可以更好地维护

Why Use Nested Classes?

There are several compelling reasons for using nested classes, among them:

  • It is a way of logically grouping classes that are only used in one place.
  • It increases encapsulation.
  • Nested classes can lead to more readable and maintainable code.

Logical grouping of classes —If a class is useful to only one other class, then it is logical to embed it in that class and keep the two together. Nesting such "helper classes" makes their package more streamlined.

Increased encapsulation —Consider two top-level classes, A and B, where B needs access to members of A that would otherwise be declared private . By hiding class B within class A, A's members can be declared private and B can access them. In addition, B itself can be hidden from the outside world.

More readable, maintainable code —Nesting small classes within top-level classes places the code closer to where it is used.

更多相关文章

  1. 安卓ScrollView嵌套RecyclerView,GridView,ViewPager冲突解决
  2. android 官方文档阅读记录-多屏幕适配
  3. Android(安卓)Web App官方文档翻译第三章:WebView构建应用
  4. 关于使用腾讯云腾讯(即时通讯SDK)遇到的问题
  5. Android(安卓)NestedScrolling嵌套滑动机制
  6. 20170524Android笔记
  7. ScrollView嵌套ViewPager,ViewPager内容不显示问题
  8. Android(安卓)UI设计 ViewPager 中嵌套HorizontalScrollView
  9. android 6.0(api 23) SDK,不再提供org.apache.http.*(只保留几个

随机推荐

  1. 浅谈Android 的事件分发机制
  2. Android之尺寸getDimension、getDimensio
  3. Android内存泄漏:谨慎使用getSystemServic
  4. Message Pool分析
  5. 细说 AppbarLayout,如何理解可折叠 Toolb
  6. Android开发者指南(2) ―― aapt
  7. Kotlin-->自定义评分控件RatingBar
  8. 2016这些Android技术会很火
  9. Android EditText文本编辑框获取焦点调出
  10. Android(安卓)OTA 升级