O'Reilly logo

Apache Jakarta and Beyond: A Java Programmer’s Introduction by Larne Pekowsky

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required