Java Basics: Anonymous Inner class application example one

Source: Internet
Author: User

One: interface

1  PackageCom.yeepay.sxf.testclassforinner;2 3 /**4 * Callback interface.5  * @authorShangxiaofei6  *7  */8  Public InterfaceCallBack {9 Ten      Public Booleanprocess (Integer a); One      A      Public BooleanDelete (Integer b); -}
View Code

Second: Business class

1  PackageCom.yeepay.sxf.testclassforinner;2 /**3 * Business class using callback interface4  * @authorShangxiaofei5  *6  */7  Public classPaymentservice {8 9     Ten      PublicString Payformoney (Integer a,callback CallBack) { OneSystem.out.println ("Paymentservice.payformoney ()" +a); AInteger m=a+100; -         if(m>100){ -             Booleanfalg=callback.process (m); the             if(falg) { -                 return"Callback.process" +m; -}Else{ -                 return"Callback.process" +m; +             } -              +}Else{ A             Booleanflag=Callback.delete (m); at             if(flag) { -                 return"Callback.delete" +m; -}Else{ -                 return"Callback.delete" +m; -             } -         } in     } -}
View Code

Three: Control class

1  PackageCom.yeepay.sxf.testclassforinner;2 /**3 * Test Class4  * @authorShangxiaofei5  *6  */7  Public classTestController {8 9     PrivatePaymentservice paymentservice=NewPaymentservice ();Ten      One     PrivateString dd= "SXF"; A      -      Public voidTestpay () { -          theString Astring=paymentservice.payformoney (100,NewCallBack () { -              - @Override -              Public Booleanprocess (Integer a) { +String mstring= ""; -                 if(a>100){ +Mstring= "SXF"; A                 } at                 if(Mstring.equals (dd)) { -                     return true; -                 } -                 return false; -             } -              in @Override -              Public BooleanDelete (Integer b) { toString mstring= ""; +                 if(b<100){ -Mstring= "SXF"; the                 } *                 if(Mstring.equals (dd)) { $                     return true;Panax Notoginseng                 } -                 return false; the             } +         }); A          the          +System.out.println ("Enclosing_type.enclosing_method ()" +astring); -     } $      $      -      Public Static voidMain (string[] args) { -TestController controller=NewTestController (); the Controller.testpay (); -     }Wuyi}
View Code

Java Basics: Anonymous Inner class application example one

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.