作者ogamenewbie (._.)
站内java
标题Re: [问题] 输入什麽就执行什麽 怎麽做
时间Tue Mar 31 01:35:02 2009
// 原文吃光光
import java.lang.reflect.Method;
public class Main {
public static void main(String[] args) throws Exception {
Class<?> c = Class.forName("Main");
Method m = c.getDeclaredMethod(args[0], new Class[]{});
m.setAccessible(true);
m.invoke(c.newInstance(), new Object[]{});
}
void dog() {
System.out.println("Bow!");
}
void cat() {
System.out.println("Meow~");
}
void pig() {
System.out.println("Oink =(0 0)= ");
}
void xyz() {
System.out.println("City Hunter!");
}
}
// 因为是手打的, 有手打错的就自行修正吧 orz
// Reflex 是错的, 应该是 Reflect 才对
// 使用方法 java Main cat
// 或 java Main dog
// 之类的, 没有 javac 过就跑来问为什麽 java 不会动的话
// 就请回去多看书吧..
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.160.34.167
1F:推 ozone:谢谢!! 03/31 22:22