WEB开发网
开发学院软件开发Java 用 BCEL 设计字节码: 直接在原方法上加指令 阅读

用 BCEL 设计字节码: 直接在原方法上加指令

 2009-09-23 00:00:00 来源:WEB开发网   
核心提示:前一个是直接生成了一个一个方法对原方法进行调用,现在直接在原方法上进行修改即将publicclassStringBuilder{privateStringbuildString(intlength){Stringresult="";for(inti=0;i<length;i++){result

前一个是直接生成了一个一个方法对原方法进行调用,现在直接在原方法上进行修改

即将

public class StringBuilder
{
    private String buildString(int length) {
        String result = "";
        for (int i = 0; i < length; i++) {
            result += (char)(i%26 + 'a');
        }
        System.out.println(result);
        return result;
    }
    
    
    public static void main(String[] argv) {
        StringBuilder inst = new StringBuilder();
        for (int i = 0; i < argv.length; i++) {
            String result = inst.buildString(Integer.parseInt(argv[i]));
            System.out.println("Constructed string of length " +
                result.length());
        }
    }
}

改成:

public class StringBuilder
{
    private String buildString(int length) {
        
        System.out.println("start start start");
        long starttime = System.currentTimeMillis();
        
        String result = "";
        for (int i = 0; i < length; i++) {
            result += (char)(i%26 + 'a');
        }
        System.out.println(result);
        
        System.out.println("Call to buildString$impl took " +
                (System.currentTimeMillis()-starttime) + " ms.");
        System.out.println("end end end end");
        
        return result;
    }
    
    
    public static void main(String[] argv) {
        StringBuilder inst = new StringBuilder();
        for (int i = 0; i < argv.length; i++) {
            String result = inst.buildString(Integer.parseInt(argv[i]));
            System.out.println("Constructed string of length " +
                result.length());
        }
    }
}

1 2  下一页

Tags:BCEL 设计 字节

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接