• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

无信不立

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

java基础之:匿名内部类应用例子一

一:接口

 1 package com.yeepay.sxf.testclassforinner;
 2 
 3 /**
 4  * 回调接口.
 5  * @author shangxiaofei
 6  *
 7  */
 8 public interface CallBack {
 9 
10     public boolean process(Integer a);
11     
12     public boolean delete(Integer b);
13 }
View Code

二:业务类

 1 package com.yeepay.sxf.testclassforinner;
 2 /**
 3  * 业务类使用回调接口
 4  * @author shangxiaofei
 5  *
 6  */
 7 public class PayMentService {
 8 
 9     
10     public String payforMoney(Integer a,CallBack callBack){
11         System.out.println("PayMentService.payforMoney()"+a);
12         Integer m=a+100;
13         if(m>100){
14             boolean falg=callBack.process(m);
15             if(falg){
16                 return "callBack.process"+m;
17             }else{
18                 return "callBack.process"+m;
19             }
20             
21         }else{
22             boolean flag=callBack.delete(m);
23             if(flag){
24                 return "callBack.delete"+m;
25             }else{
26                 return "callBack.delete"+m;
27             }
28         }
29     }
30 }
View Code

三:控制类

 1 package com.yeepay.sxf.testclassforinner;
 2 /**
 3  * 测试类
 4  * @author shangxiaofei
 5  *
 6  */
 7 public class TestController {
 8 
 9     private PayMentService payMentService=new PayMentService();
10     
11     private String dd="sxf";
12     
13     public void testPay(){
14         
15         String aString=payMentService.payforMoney(100, new CallBack() {
16             
17             @Override
18             public boolean process(Integer a) {
19                 String mString="";
20                 if(a>100){
21                     mString="sxf";
22                 }
23                 if(mString.equals(dd)){
24                     return true;
25                 }
26                 return false;
27             }
28             
29             @Override
30             public boolean delete(Integer b) {
31                 String mString="";
32                 if(b<100){
33                     mString="sxf";
34                 }
35                 if(mString.equals(dd)){
36                     return true;
37                 }
38                 return false;
39             }
40         });
41         
42         
43         System.out.println("enclosing_type.enclosing_method()"+aString);
44     }
45     
46     
47     public static void main(String[] args) {
48         TestController controller=new TestController();
49         controller.testPay();
50     }
51 }
View Code

 

posted on 2016-08-15 18:33  无信不立  阅读(311)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3