25
2016/02
概述一言以蔽之,内部类就是将一个类的定义放在另一个类的定义内部内部类在平常的编码过程中应用的场景并不多,本文主要来总结一下内部类的特性和用法 下面的例子展示了内部类组织代码和名字隐藏的功能:package com.techlog.test;
/**
* Created by techlog on 16/2/24.
*/
public class Parcel2 {
private class Destination {
private String label;
Destination(String whereTo) {
label = whereTo;
}
String readLabel() {
return label;
}
}
public Destination to(String s) {
return new Destination(s);
}
public void ship(String dest) {
Destination d = to(dest);
System.out.println(d.readLabel());
}
#技术帖
#龙潭书斋
#class
#java