Java·´ÉäÖÐMethodÀàinvoke·½·¨µÄÓ÷¨
/**
* InvokeTester.java
* °æȨËùÓÐ(C) 2010 cuiran2001@163.com
* ´´½¨:´ÞȽ 2010-2-9 ÏÂÎç02:07:13
*/
package com.timer.demo.objectsocket;
import java.lang.reflect.Method;
/**
* @author ´ÞȽ
*
*/
public class InvokeTester {
public int add(int param1, int param2) {
return param1 + param2;
}
public String echo(String mesg) {
return "echo" + mesg;
}
public static void main(String[] args) throws Exception {
Class classType = InvokeTester.class;
Object invokertester = classType.newInstance();
Method addMethod = classType.getMethod("add", new Class[] { int.class,
int.class });
//MethodÀàµÄinvoke(Object obj,Object args[])·½·¨½ÓÊյIJÎÊý±ØÐëΪ¶ÔÏó£¬
//Èç¹û²ÎÊýΪ»ù±¾ÀàÐÍÊý¾Ý£¬±ØÐëת»»ÎªÏàÓ¦µÄ°ü×°ÀàÐ͵ĶÔÏó¡£invoke()·½·¨µÄ·µ»ØÖµ×ÜÊǶÔÏó£¬
//Èç¹ûʵ¼Ê±»µ÷Óõķ½·¨µÄ·µ»ØÀàÐÍÊÇ»ù±¾ÀàÐÍÊý¾Ý£¬ÄÇôinvoke()·½·¨»á°ÑËüת»»ÎªÏàÓ¦µÄ°ü×°ÀàÐ͵ĶÔÏó£¬
//ÔÙ½«Æä·µ»Ø
Object result = addMethod.invoke(invokertester, new Object[] {
new Integer(100), new Integer(200) });
//ÔÚjdk5.0ÖÐÓÐÁË×°Ïä ²ðÏä»úÖÆ new Integer(100)¿ÉÒÔÓÃ100À´´úÌ棬ϵͳ»á×Ô¶¯ÔÚint ºÍintegerÖ®¼äת»»
System.out.println(result);
Method echoMethod = classType.getMethod("echo",
new Class[] { String.class });
result = echoMethod.invoke(invokertester, new Object[] { "hello"});
System.out.println(result);
}
}
Ïà¹ØÎĵµ£º
ʹÓÃÀàjava.io.File
1.»ñȡϵͳӲÅÌÐÅÏ¢£º
public static String getDiskInfo() {
StringBuffer sb=new StringBuffer();
File[] roots = File.listRoots();// »ñÈ¡´ÅÅÌ·ÖÇøÁбí
for (File file : roots) {
long totalSpace=file.getTotalSpace();
long freeSpace=file.getFreeSpace();
long usa ......
×î½üÓ¦ÀÏʦµÄÒªÇó¿´ÁËÊý¾Ý¿â¡£ÔÚÍøÉÏÕÒÁËÊÓƵ£¬ÊǸö½ÌÓý»ú¹¹·¢µÄ¡£ÄǸöÊÓƵ¿´µÃÎÒÖ±·¸À§£¬³ýÁËÀÏʦ½²¿Î½²´íµÄʱºò¡£
ÊÓƵ½²µÃºÜdzÏÔ£¬µÚÒ»Õ½²ÁËsqlÊý¾Ý¿â½á¹¹£¬ÓÐʲôģÐÍ¡£½Ó׎²Ö÷¼ü£¬Íâ¼ü£¬È»ºóÊǽ¨±íÓï¾ä£¬²éѯÓï¾äµÈµÈ¡£
show databases ÏÔʾÊý¾Ý¿â¡£
use ** ʹÓÃÊý¾Ý¿â¡£
create table ** (**,**,**) ½¨±í¡£
se ......
Object Ordering
A List l may be sorted as follows.
Collections.sort(l);
If the List consists of String elements, it will be sorted into alphabetical order. If it consists of Date elements, it will be sorted into chronological order. How does this happen? String and Date both implement the Compara ......
ǰЩÈÕ×ÓÕÛÌÚµÄÔÚÏßÅÄÕÕ£¬ÓÉÓÚÖ»ÊǸüÐÂblob×ֶΣ¬Ã»ÓÐÔÚ±¾µØ±£´æÕÕƬ£¬µ¼Ö¿ͻ§ÅÄÄÔÃÅÏëÒªµÄʱºò²»ÄÜÂíÉÏÄóöÀ´¡£Ã»ËµµÄËÈù˿ÍÊÇÉϵÛÄØ£¬×ö°É¡£Ê¹ÓÃÏ̳߳ش´½¨Èý¸öÏß³ÌÈÃ×Ô¶¨Ò»¸öÏß³ÌÄ¿±ê¹²Ïí£¨Ò²¾ÍÊǰѱíÀïµÄ¼Ç¼·Ö³Én×éͬʱִÐе¼³ö£©¡£³ÌÐòºÜ¼òµ¥£¬Ò»¹²ËĸöÀàºÍÒ»¸öojdbc14.jar°ü¡£ÓÉÓÚsqlÓï¾äд´íÁËÔì³É¶à¸öÏ̶߳ÔÒ»¸ ......
µÚ1Õ JavaÓïÑÔ¸ÅÊö
1.1 ֪ʶ¸ÅÀ¨
1.2 ʵÑéÁ·Ï°
1.2.1 Ò»¸ö¼òµ¥µÄÓ¦ÓóÌÐò
classÀï²»ÄÜÔÙÓÐclass£¬ÎÞÂÛÓÐûÓÐpublicÐÞÊΣ¬class¶¼ÊÇƽÐйØϵ£¬ÔÚbinÎļþ¼ÐÖлá²úÉú¸÷×ÔµÄ×Ö½ÚÂëÎļþ¡£Í¬Ò»¸ö.javaÔ´ÎļþÖÐÖÁ¶àÓÐÒ»¸öpublic class£¬Èç¹û²»ÏëÔÙÒ»¸öÔ´ÎļþÖÐд¶à¸öÀ࣬¾Í¸÷×ÔдԴ³ÌÐò£¬²¢°ÑÀ๫Ó㬼´ÓÃpublicÐÞÊΡ£
1.2.2 ......