1、枚举类型的类,不仅仅只有数据,也可以存在函数
2、枚举类型中存在的方法在编译的时候会把其中的方法编译成静态内部类
public enum Api {
http() {
public MsgHelper getHandler() {
// TODO Auto-generated method stub
return MsgManager.getInstance();
}
};
public abstract GenericHelper getHandler();
public GenericHelper getHandler(int type, Map<String, Object> args) {
return null;
}
}
在枚举类型中定义一个这样的方法——http,而在解析成.class的时候是生成了一个静态内部类,
Api.http.getHandler()调用的其实是Api中http的静态内部类的引用。
相当于下面的代码
package com.example.tap2;
public class text {
private static class http extends text{
public void getHandler(){
}
}
private http h = new http();
public void getHandler(){
}
}