Java Reflection 2 Class’a Ait Metotlari Listelemek

public class Person {
  public final static int ID = 0;
  private String name,surname;
  private int age;
  private static List<Person> persons = new ArrayList<>();
  
  public Person() {}
  
  public Person(String name,String surname,int age) {
    this.name=name;
    this.surname=surname;
    this.age = age;
  }
  
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }
  public String getSurname() {
    return surname;
  }
  public void setSurname(String surname) {
    this.surname = surname;
  }
  public int getAge() {
    return age;
  }
  public void setAge(int age) {
    this.age = age;
  }
  
  public static void addToList(Person person) {
    persons.add(person);
  }
  
  public static List<Person> getPersons() {
    return persons;
  }
}

Method[] methods = Person.class.getDeclaredMethods();
for(Method method: methods) {
  System.out.print(Modifier.toString(method.getModifiers())+" "
      +method.getReturnType()+" "
      +method.getName());
  Parameter[] parameters = method.getParameters();
  System.out.print("(");
  for(Parameter param : parameters) {
    System.out.print(param.getType()+" "+param.getName()+",");
  }
  System.out.println(")");
}
public static void addToList(class com.dogukan.b1.Person arg0,)
public class java.lang.String getSurname()
public void setSurname(class java.lang.String arg0,)
public int getAge()
public void setAge(int arg0,)
public static interface java.util.List getPersons()
public class java.lang.String getName()
public void setName(class java.lang.String arg0,)

 

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *