????????--Java???????????
???????????? ???????[ 2013/8/28 10:01:22 ] ????????
????????????????????java.util.LinkedList??java.util.ArrayList??get(intindex)?????????ArrayList???LinkedList??Ч??????????????????????????????????
?????????????????????
publicinterfaceFoo{
publicvoidtestArrayList();
publicvoidtestLinkedList();
}
??????????????????????????????
publicclassFooImplimplementsFoo{
privateListlink=newLinkedList();
privateListarray=newArrayList();
publicFooImpl()
{
for(inti=0;i<10000;i++)
{
array.add(newInteger(i));
link.add(newInteger(i));
}
}
publicvoidtestArrayList()
{
for(inti=0;i<10000;i++)
array.get(i);
}
publicvoidtestLinkedList()
{
for(inti=0;i<10000;i++)
link.get(i);
}
}
??????????????????????????????InvocationHandler???
importjava.lang.reflect.InvocationHandler;
importjava.lang.reflect.Method;
importjava.lang.reflect.*;
publicclassHandlerimplementsInvocationHandler{
privateObjectobj;
publicHandler(Objectobj){
this.obj=obj;
}
publicstaticObjectnewInstance(Objectobj){
Objectresult=Proxy.newProxyInstance(obj.getClass().getClassLoader()??
obj.getClass().getInterfaces()??newHandler(obj));
return(result);
}
publicObjectinvoke(Objectproxy??Methodmethod??Object[]args)throwsThrowable{
Objectresult;
try{
System.out.print("beginmethod"+method.getName()+"(");
for(inti=0;args!=null&&i<args.length;i++){
if(i>0)System.out.print("??");
System.out.print(""+
args[i].toString());
}
System.out.println(")");
longstart=System.currentTimeMillis();
result=method.invoke(obj??args);
longend=System.currentTimeMillis();
System.out.println("themethod"+method.getName()+"lasts"+(end-start)+"ms");
}catch(InvocationTargetExceptione){
throwe.getTargetException();
}catch(Exceptione){
thrownewRuntimeException
("unexpectedinvocationexception:"+
e.getMessage());
}finally{
System.out.println("endmethod"+method.getName());
}
returnresult;
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11