java 循环打印出某对象所在类的类名和方法
java 循环打印出某对象所在类的类名和方法
public class A {
public void b(){}
public void c(){}
public void d(){}
public void e(){}
}
import java.lang.reflect.*;
public class StaticTest {
public static void test(Object obj)
{
Class myclass = obj.getClass();
//System.out.println(myclass.getName());
Method[] mymethods = myclass.getDeclaredMethods();
int n = mymethods.length;
for(int i=0; i<n; i++)
{
System.out.println("类名:"+myclass.getName()+"; 方法名:"+mymethods[i].getName());
}
}
public static void main(String args[]){
A a = new A();
test(a);
}
}
相关文档:
int temp;
int [] arr=new int[];
for(int i=0;i<arr.length;i++)
{
for(int j=0;j<arr.length-i-1;j++)
{
if(arr[j]<arr[j+1])
{
& ......
import java.io.*;
public class FileToFile
{
public static void main(String[] args)
{
File fold = new File("e:\\java\\file.java");//某路径下的文件
String strNewPath = "e:\\java\\new file\\";//新路径
File fnewpath = new File(strNewPath);
......
JDK1.4中
Map map = new HashMap();
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
Object key = entry.getKey();
Object value = entry.getValue();
}
JDK1.5中,应用新特性For-Each循环
Map m = new HashMap();
......
example: 求5的阶乘。。
如下:
public class Test {
static int multiply(int n){
if(n==1||n==0)
return n;
else
return n*multiply(n-1);
}
public static void main(String[] args){
System.out.println(multiply(10));
}
......