|
|
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Classobjects represent interfaces as well as classes. If you aren't sure whether aClassobject represents an interface or a class, call theisInterfacemethod.You invoke
Classmethods to get information about an interface. To find the public constants of an interface, invoke thegetFieldsmethod upon theClassobject that represents the interface. The section Identifying Class Fields has an example containinggetFields. You can usegetMethodsto get information about an interface's methods. See the section Obtaining Method Information. To find out about an interface's modifiers, invoke thegetModifiersmethod. See the section Discovering Class Modifiers for an example.By calling
isInterface, the following program reveals thatObserveris an interface and thatObservableis a class:The output of the preceding program is:import java.lang.reflect.*; import java.util.*; class SampleCheckInterface { public static void main(String[] args) { Class observer = Observer.class; Class observable = Observable.class; verifyInterface(observer); verifyInterface(observable); } static void verifyInterface(Class c) { String name = c.getName(); if (c.isInterface()) { System.out.println(name + " is an interface."); } else { System.out.println(name + " is a class."); } } }java.util.Observer is an interface. java.util.Observable is a class.
|
|
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2004 Sun Microsystems, Inc. All rights reserved.