java程序员-http://www.it-ebooks.info/

年轻的我,脚踩大地,仰望天空,路还很长....

博客园 首页 新随笔 联系 订阅 管理
1.开发中如何使用枚举,一般在开发中使用消息提示。枚举可以继承,实现接口等。
public enum Result { SUCCESS(1,"201 ok") { @Override void doCallBack(String msg) { System.out.println("201 success process!!!" + "\t" + msg); } }, ERROR(2,"501 server error") { @Override void doCallBack(String msg) { System.out.println("server error process !!!" + "\t" + msg); } }, FAIRL(3,"javascript error") { @Override void doCallBack(String msg) { System.out.println("javascript error process!!!" + "\t" + msg); } }; private int code; private String msg; abstract void doCallBack(String msg); Result(int code,String msg){ this.code = code; this.msg = msg; } public static void main(String[] args) { Result v = Result.ERROR; v.doCallBack(v.msg); } }

  

posted on 2015-12-27 18:55  gstsyyb  阅读(160)  评论(0编辑  收藏  举报