Appendix . Appendix A

A.1 Dynamic Proxies

It is well known that a class can implement any number of interfaces at compile time by specifying the list of interface names and providing implementations of the required methods. Any class that implements an interface may be cast to the interface type at run time. A typical, if simple, example is shown in Listing A.1.

Example A.1. A simple interface and its use

public Interface MyInterface {
     public void sayHello();
}

pubilc class MyClass implements MyInterface {
    public void sayHello() {
        System.out.println("Hello, world");
    }
}

public class MyDemo {
    public static void main(String argv[]) {
        MyClass c     = new MyClass();


         MyInterface i = (MyInterface) c;
         i.sayHello();
     }
}

In this example the cast to MyInterface ...

Get Apache Jakarta and Beyond: A Java Programmer’s Introduction now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.