免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
xlincn的博客
 學(xué)習(xí)reflect(一)

一點(diǎn)點(diǎn)小代碼


import java.lang.reflect.*;
/** A program that displays a class synopsis for the named class */
public class ShowClass {
    /** The main method.  Print info about the named class */
    public static void main(String[] args) throws ClassNotFoundException {
        Class c = Class.forName(args[0]);
        print_class(c);
    }
   
    /**
     * Display the modifiers, name, superclass and interfaces of a class
     * or interface. Then go and list all constructors, fields, and methods.
     **/
    public static void print_class(Class c)
    {
        // Print modifiers, type (class or interface), name and superclass.
        if (c.isInterface()) {
            // The modifiers will include the "interface" keyword here...
            System.out.print(Modifier.toString(c.getModifiers()) + " " +
        typename(c));
        }
        else if (c.getSuperclass() != null) {
            System.out.print(Modifier.toString(c.getModifiers()) + " class " +
        typename(c) +
        " extends " + typename(c.getSuperclass()));
 }
        else {
            System.out.print(Modifier.toString(c.getModifiers()) + " class " +
        typename(c));
 }
 
        // Print interfaces or super-interfaces of the class or interface.
        Class[] interfaces = c.getInterfaces();
        if ((interfaces != null)&& (interfaces.length > 0)) {
            if (c.isInterface()) System.out.print(" extends ");
            else System.out.print(" implements ");
            for(int i = 0; i < interfaces.length; i++) {
                if (i > 0) System.out.print(", ");
                System.out.print(typename(interfaces[i]));
            }
        }
 
        System.out.println(" {");            // Begin class member listing.
 
        // Now look up and display the members of the class.
        System.out.println("  // Constructors");
        Constructor[] constructors = c.getDeclaredConstructors();
        for(int i = 0; i < constructors.length; i++)   // Display constructors.
            print_method_or_constructor(constructors[i]);
 
        System.out.println("  // Fields");
        Field[] fields = c.getDeclaredFields();           // Look up fields.
        for(int i = 0; i < fields.length; i++)            // Display them.
            print_field(fields[i]);
 
        System.out.println("  // Methods");
        Method[] methods = c.getDeclaredMethods();        // Look up methods.
        for(int i = 0; i < methods.length; i++)           // Display them.
            print_method_or_constructor(methods[i]);
 
        System.out.println("}");             // End class member listing.
    }
   
    /** Return the name of an interface or primitive type, handling arrays. */
    public static String typename(Class t) {
        String brackets = "";
        while(t.isArray()) {
            brackets += "[]";
            t = t.getComponentType();
        }
 String name = t.getName();
 int pos = name.lastIndexOf(‘.‘);
 if (pos != -1) name = name.substring(pos+1);
 return name + brackets;
    }
   
    /** Return a string version of modifiers, handling spaces nicely. */
    public static String modifiers(int m) {
        if (m == 0) return "";
        else return Modifier.toString(m) + " ";
    }
   
    /** Print the modifiers, type, and name of a field */
    public static void print_field(Field f) {
        System.out.println("  " + modifiers(f.getModifiers()) +
      typename(f.getType()) + " " + f.getName() + ";");
    }
   
    /**
     * Print the modifiers, return type, name, parameter types and exception
     * type of a method or constructor.  Note the use of the Member interface
     * to allow this method to work with both Method and Constructor objects
     **/
    public static void print_method_or_constructor(Member member) {
        Class returntype=null, parameters[], exceptions[];
        if (member instanceof Method) {
            Method m = (Method) member;
            returntype = m.getReturnType();
            parameters = m.getParameterTypes();
            exceptions = m.getExceptionTypes();
     System.out.print("  " + modifiers(member.getModifiers()) +
        typename(returntype) + " " + member.getName() +
        "(");
        } else {
            Constructor c = (Constructor) member;
            parameters = c.getParameterTypes();
            exceptions = c.getExceptionTypes();
     System.out.print("  " + modifiers(member.getModifiers()) +
        typename(c.getDeclaringClass()) + "(");
        }
 
        for(int i = 0; i < parameters.length; i++) {
            if (i > 0) System.out.print(", ");
            System.out.print(typename(parameters[i]));
        }
        System.out.print(")");
        if (exceptions.length > 0) System.out.print(" throws ");
        for(int i = 0; i < exceptions.length; i++) {
            if (i > 0) System.out.print(", ");
            System.out.print(typename(exceptions[i]));
        }
        System.out.println(";");
    }
}
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
通過反射方式來調(diào)用某個(gè)對(duì)象的方法的步驟
C#面試題(英文)
Difference between Abstract Class and Interface in java | Java Code Geeks
Java Annotation詳解
Tiger系列四:Annotation第二部分:定制Annotation
[emacs][delphi] 跳到函數(shù)聲明/實(shí)現(xiàn)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服