package com.shrimpking.t5;
/**
* Created by IntelliJ IDEA.
*
* @Author : Shrimpking
* @create 2024/9/12 15:45
*/
public class MyClass
{
public int pubField;
protected int proField;
private int priField;
public MyClass(){}
public MyClass(int a){}
public MyClass(int a,int b){}
public MyClass(int a,int b,int c){}
public void pubMethod(){}
protected void proMethod(){}
void defMethod(){}
private void priMethod(){}
public static void staticMethod(){}
}
package com.shrimpking.t5;
/**
* Created by IntelliJ IDEA.
*
* @Author : Shrimpking
* @create 2024/9/12 15:49
*/
public interface MyInterface
{
float pi = 3.14f;
void fun();
default void defFunc(){}
static void staticFunc(){}
// private void priFunc(){}
}
package com.shrimpking.t5;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* Created by IntelliJ IDEA.
*
* @Author : Shrimpking
* @create 2024/9/12 15:50
*/
public class ClassInfo
{
public static void main(String[] args)
{
Class clz = MyClass.class;
System.out.println("Fields:");
//获取公共字段
for (Field f : clz.getFields()){
System.out.println(f);
}
System.out.println("----");
System.out.println("Constructors:");
//获取所有声明的构造器
for (Constructor c: clz.getDeclaredConstructors()){
System.out.println(c);
}
System.out.println("----");
System.out.println("Methods:");
//获取公共方法,包含Object继承的公共方法
for (Method m : clz.getMethods()){
System.out.println(m);
}
System.out.println("----");
clz = MyInterface.class;
System.out.println("Interface Method:");
for (Method m : clz.getMethods()){
System.out.println(m);
}
}
}
标签:ClassInfo,int,void,System,println,public,out
From: https://blog.51cto.com/u_15356972/12016818