Java.lang.Class.getMethods() 方法
描述
java.lang.Class.getMethods() 返回一个包含 Method 对象的数组,该对象反映了该 Class 对象所代表的类或接口的所有公共成员方法,包括类或接口声明的那些和那些 继承自超类和超接口。
如果此 Class 对象表示没有公共成员方法的类或接口,或者此 Class 对象表示原始类型或 void,则该方法返回长度为 0 的数组。
声明
以下是 java.lang.Class.getMethods() 方法的声明。
public Method[] getMethods() throws SecurityException
参数
NA
返回值
此方法返回表示该类的公共方法的 Method 对象数组。
异常
SecurityException − 如果存在安全管理员 s。
示例
下面的例子展示了 java.lang.Class.getMethods() 方法的使用。
package com.tutorialspoint; import java.lang.reflect.*; public class ClassDemo { public static void main(String[] args) { try { Class cls = Class.forName("java.awt.Label"); System.out.println("Methods ="); /* returns the array of Method objects representing the public methods of this class */ Method m[] = cls.getMethods(); for(int i = 0; i < m.length; i++) { System.out.println(m[i]); } } catch (Exception e) { System.out.println("Exception: " + e); } } }
让我们编译并运行上面的程序,这将产生下面的结果 −
Methods = public void java.awt.Label.addNotify() public int java.awt.Label.getAlignment() public synchronized void java.awt.Label.setAlignment(int) public java.lang.String java.awt.Label.getText() public void java.awt.Label.setText(java.lang.String) public javax.accessibility.AccessibleContext java.awt.Label.getAccessibleContext() public void java.awt.Component.add(java.awt.PopupMenu) public java.lang.String java.awt.Component.toString() public java.lang.String java.awt.Component.getName() public java.awt.Dimension java.awt.Component.size() public boolean java.awt.Component.contains(int,int) public boolean java.awt.Component.contains(java.awt.Point) public java.awt.Container java.awt.Component.getParent() public java.awt.Point java.awt.Component.getLocation() public java.awt.Point java.awt.Component.getLocation(java.awt.Point) public void java.awt.Component.remove(java.awt.MenuComponent) public void java.awt.Component.setName(java.lang.String) public void java.awt.Component.list() public void java.awt.Component.list(java.io.PrintStream) public void java.awt.Component.list(java.io.PrintStream,int) public void java.awt.Component.list(java.io.PrintWriter) public void java.awt.Component.list(java.io.PrintWriter,int) public void java.awt.Component.print(java.awt.Graphics) public java.awt.Dimension java.awt.Component.getSize() public java.awt.Dimension java.awt.Component.getSize(java.awt.Dimension) public void java.awt.Component.resize(int,int) public void java.awt.Component.resize(java.awt.Dimension) public boolean java.awt.Component.action(java.awt.Event,java.lang.Object) public void java.awt.Component.setSize(int,int) public void java.awt.Component.setSize(java.awt.Dimension) public void java.awt.Component.update(java.awt.Graphics) public boolean java.awt.Component.isOpaque() public void java.awt.Component.enable() public void java.awt.Component.enable(boolean) public void java.awt.Component.disable() public java.awt.Point java.awt.Component.location() public final java.lang.Object java.awt.Component.getTreeLock() public java.awt.Toolkit java.awt.Component.getToolkit() public java.awt.peer.ComponentPeer java.awt.Component.getPeer() public synchronized void java.awt.Component.setDropTarget(java.awt.dnd.DropTarget) public synchronized java.awt.dnd.DropTarget java.awt.Component.getDropTarget() public java.awt.GraphicsConfiguration java.awt.Component.getGraphicsConfiguration() public boolean java.awt.Component.isValid() public boolean java.awt.Component.isDisplayable() public boolean java.awt.Component.isVisible() public java.awt.Point java.awt.Component.getMousePosition() throws java.awt.HeadlessException public boolean java.awt.Component.isShowing() public boolean java.awt.Component.isEnabled() public void java.awt.Component.setEnabled(boolean) public boolean java.awt.Component.isDoubleBuffered() public void java.awt.Component.enableInputMethods(boolean) public void java.awt.Component.setVisible(boolean) public void java.awt.Component.show() public void java.awt.Component.show(boolean) public void java.awt.Component.hide() public java.awt.Color java.awt.Component.getForeground() public void java.awt.Component.setForeground(java.awt.Color) public boolean java.awt.Component.isForegroundSet() public java.awt.Color java.awt.Component.getBackground() public void java.awt.Component.setBackground(java.awt.Color) public boolean java.awt.Component.isBackgroundSet() public java.awt.Font java.awt.Component.getFont() public void java.awt.Component.setFont(java.awt.Font) public boolean java.awt.Component.isFontSet() public java.util.Locale java.awt.Component.getLocale() public void java.awt.Component.setLocale(java.util.Locale) public java.awt.image.ColorModel java.awt.Component.getColorModel() public java.awt.Point java.awt.Component.getLocationOnScreen() public void java.awt.Component.setLocation(int,int) public void java.awt.Component.setLocation(java.awt.Point) public void java.awt.Component.move(int,int) public java.awt.Rectangle java.awt.Component.getBounds() public java.awt.Rectangle java.awt.Component.getBounds(java.awt.Rectangle) public java.awt.Rectangle java.awt.Component.bounds() public void java.awt.Component.setBounds(int,int,int,int) public void java.awt.Component.setBounds(java.awt.Rectangle) public void java.awt.Component.reshape(int,int,int,int) public int java.awt.Component.getX() public int java.awt.Component.getY() public int java.awt.Component.getWidth() public int java.awt.Component.getHeight() public boolean java.awt.Component.isLightweight() public void java.awt.Component.setPreferredSize(java.awt.Dimension) public java.awt.Dimension java.awt.Component.preferredSize() public boolean java.awt.Component.isPreferredSizeSet() public java.awt.Dimension java.awt.Component.getPreferredSize() public void java.awt.Component.setMinimumSize(java.awt.Dimension) public java.awt.Dimension java.awt.Component.minimumSize() public boolean java.awt.Component.isMinimumSizeSet() public java.awt.Dimension java.awt.Component.getMinimumSize() public void java.awt.Component.setMaximumSize(java.awt.Dimension) public boolean java.awt.Component.isMaximumSizeSet() public java.awt.Dimension java.awt.Component.getMaximumSize() public float java.awt.Component.getAlignmentX() public float java.awt.Component.getAlignmentY() public int java.awt.Component.getBaseline(int,int) public java.awt.Component$BaselineResizeBehavior java.awt.Component.getBaselineResizeBehavior() public void java.awt.Component.doLayout() public void java.awt.Component.layout() public void java.awt.Component.validate() public void java.awt.Component.invalidate() public java.awt.Graphics java.awt.Component.getGraphics() public java.awt.FontMetrics java.awt.Component.getFontMetrics(java.awt.Font) public void java.awt.Component.setCursor(java.awt.Cursor) public java.awt.Cursor java.awt.Component.getCursor() public boolean java.awt.Component.isCursorSet() public void java.awt.Component.paint(java.awt.Graphics) public void java.awt.Component.paintAll(java.awt.Graphics) public void java.awt.Component.repaint() public void java.awt.Component.repaint(long) public void java.awt.Component.repaint(int,int,int,int) public void java.awt.Component.repaint(long,int,int,int,int) public void java.awt.Component.printAll(java.awt.Graphics) public boolean java.awt.Component.imageUpdate(java.awt.Image,int,int,int,int,int) public java.awt.Image java.awt.Component.createImage(java.awt.image.ImageProducer) public java.awt.Image java.awt.Component.createImage(int,int) public java.awt.image.VolatileImage java.awt.Component.createVolatileImage(int,int) public java.awt.image.VolatileImage java.awt.Component.createVolatileImage(int,int,java.awt.ImageCapabilities) throws java.awt.AWTException public boolean java.awt.Component.prepareImage(java.awt.Image,java.awt.image.ImageObserver) public boolean java.awt.Component.prepareImage (java.awt.Image,int,int,java.awt.image.ImageObserver) public int java.awt.Component.checkImage(java.awt.Image,java.awt.image.ImageObserver) public int java.awt.Component.checkImage (java.awt.Image,int,int,java.awt.image.ImageObserver) public void java.awt.Component.setIgnoreRepaint(boolean) public boolean java.awt.Component.getIgnoreRepaint() public boolean java.awt.Component.inside(int,int) public java.awt.Component java.awt.Component.getComponentAt(int,int) public java.awt.Component java.awt.Component.getComponentAt(java.awt.Point) public java.awt.Component java.awt.Component.locate(int,int) public void java.awt.Component.deliverEvent(java.awt.Event) public final void java.awt.Component.dispatchEvent(java.awt.AWTEvent) public boolean java.awt.Component.postEvent(java.awt.Event) public synchronized void java.awt.Component.addComponentListener(java.awt.event.ComponentListener) public synchronized void java.awt.Component.removeComponentListener(java.awt.event.ComponentListener) public synchronized java.awt.event.ComponentListener[] java.awt.Component.getComponentListeners() public synchronized void java.awt.Component.addFocusListener(java.awt.event.FocusListener) public synchronized void java.awt.Component.removeFocusListener(java.awt.event.FocusListener) public synchronized java.awt.event.FocusListener[] java.awt.Component.getFocusListeners() public void java.awt.Component.addHierarchyListener(java.awt.event.HierarchyListener) public void java.awt.Component.removeHierarchyListener(java.awt.event.HierarchyListener) public synchronized java.awt.event.HierarchyListener[] java.awt.Component.getHierarchyListeners() public void java.awt.Component.addHierarchyBoundsListener (java.awt.event.HierarchyBoundsListener) public void java.awt.Component.removeHierarchyBoundsListener (java.awt.event.HierarchyBoundsListener) public synchronized java.awt.event.HierarchyBoundsListener[] java.awt.Component.getHierarchyBoundsListeners() public synchronized void java.awt.Component.addKeyListener(java.awt.event.KeyListener) public synchronized void java.awt.Component.removeKeyListener(java.awt.event.KeyListener) public synchronized java.awt.event.KeyListener[] java.awt.Component.getKeyListeners() public synchronized void java.awt.Component.addMouseListener(java.awt.event.MouseListener) public synchronized void java.awt.Component.removeMouseListener(java.awt.event.MouseListener) public synchronized java.awt.event.MouseListener[] java.awt.Component.getMouseListeners() public synchronized void java.awt.Component.addMouseMotionListener(java.awt.event.MouseMotionListener) public synchronized void java.awt.Component.removeMouseMotionListener (java.awt.event.MouseMotionListener) public synchronized java.awt.event.MouseMotionListener[] java.awt.Component.getMouseMotionListeners() public synchronized void java.awt.Component.addMouseWheelListener(java.awt.event.MouseWheelListener) public synchronized void java.awt.Component.removeMouseWheelListener(java.awt.event.MouseWheelListener) public synchronized java.awt.event.MouseWheelListener[] java.awt.Component.getMouseWheelListeners() public synchronized void java.awt.Component.addInputMethodListener(java.awt.event.InputMethodListener) public synchronized void java.awt.Component.removeInputMethodListener (java.awt.event.InputMethodListener) public synchronized java.awt.event.InputMethodListener[] java.awt.Component.getInputMethodListeners() public java.util.EventListener[] java.awt.Component.getListeners(java.lang.Class) public java.awt.im.InputMethodRequests java.awt.Component.getInputMethodRequests() public java.awt.im.InputContext java.awt.Component.getInputContext() public boolean java.awt.Component.handleEvent(java.awt.Event) public boolean java.awt.Component.mouseDown(java.awt.Event,int,int) public boolean java.awt.Component.mouseDrag(java.awt.Event,int,int) public boolean java.awt.Component.mouseUp(java.awt.Event,int,int) public boolean java.awt.Component.mouseMove(java.awt.Event,int,int) public boolean java.awt.Component.mouseEnter(java.awt.Event,int,int) public boolean java.awt.Component.mouseExit(java.awt.Event,int,int) public boolean java.awt.Component.keyDown(java.awt.Event,int) public boolean java.awt.Component.keyUp(java.awt.Event,int) public void java.awt.Component.removeNotify() public boolean java.awt.Component.gotFocus(java.awt.Event,java.lang.Object) public boolean java.awt.Component.lostFocus(java.awt.Event,java.lang.Object) public boolean java.awt.Component.isFocusTraversable() public boolean java.awt.Component.isFocusable() public void java.awt.Component.setFocusable(boolean) public void java.awt.Component.setFocusTraversalKeys(int,java.util.Set) public java.util.Set java.awt.Component.getFocusTraversalKeys(int) public boolean java.awt.Component.areFocusTraversalKeysSet(int) public void java.awt.Component.setFocusTraversalKeysEnabled(boolean) public boolean java.awt.Component.getFocusTraversalKeysEnabled() public void java.awt.Component.requestFocus() public boolean java.awt.Component.requestFocusInWindow() public java.awt.Container java.awt.Component.getFocusCycleRootAncestor() public boolean java.awt.Component.isFocusCycleRoot(java.awt.Container) public void java.awt.Component.transferFocus() public void java.awt.Component.nextFocus() public void java.awt.Component.transferFocusBackward() public void java.awt.Component.transferFocusUpCycle() public boolean java.awt.Component.hasFocus() public boolean java.awt.Component.isFocusOwner() public void java.awt.Component.addPropertyChangeListener(java.beans.PropertyChangeListener) public void java.awt.Component.addPropertyChangeListener (java.lang.String,java.beans.PropertyChangeListener) public void java.awt.Component.removePropertyChangeListener (java.beans.PropertyChangeListener) public void java.awt.Component.removePropertyChangeListener (java.lang.String,java.beans.PropertyChangeListener) public java.beans.PropertyChangeListener[] java.awt.Component.getPropertyChangeListeners() public java.beans.PropertyChangeListener[] java.awt.Component.getPropertyChangeListeners(java.lang.String) public void java.awt.Component.firePropertyChange(java.lang.String,byte,byte) public void java.awt.Component.firePropertyChange(java.lang.String,char,char) public void java.awt.Component.firePropertyChange(java.lang.String,short,short) public void java.awt.Component.firePropertyChange(java.lang.String,long,long) public void java.awt.Component.firePropertyChange(java.lang.String,float,float) public void java.awt.Component.firePropertyChange(java.lang.String,double,double) public void java.awt.Component.setComponentOrientation(java.awt.ComponentOrientation) public java.awt.ComponentOrientation java.awt.Component.getComponentOrientation() public void java.awt.Component.applyComponentOrientation(java.awt.ComponentOrientation) public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException public final void java.lang.Object.wait() throws java.lang.InterruptedException public boolean java.lang.Object.equals(java.lang.Object) public native int java.lang.Object.hashCode() public final native java.lang.Class java.lang.Object.getClass() public final native void java.lang.Object.notify() public final native void java.lang.Object.notifyAll()