Skip to Content
Apache Jakarta and Beyond: A Java Programmer’s Introduction
book

Apache Jakarta and Beyond: A Java Programmer’s Introduction

by Larne Pekowsky
December 2004
Intermediate to advanced content levelIntermediate to advanced
608 pages
11h 47m
English
Addison-Wesley Professional
Content preview from Apache Jakarta and Beyond: A Java Programmer’s Introduction

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java 9 High Performance

Java 9 High Performance

Mayur Ramgir, Nick Samoylov

Publisher Resources

ISBN: 0321237714Purchase book