java reflection örrneği

Java Reflection 5 Class Metot’u Cagirmak(invoke)

public class Person { public int alfa(String a) { return a.length(); } public static String beta(int a) { return “a+5=”+(a+5); } } Person person = new Person(); try { // instance method call Method method = person.getClass().getMethod(“alfa”,String.class); int a = (int) method.invoke(person, “dogukan”); System.out.println(a); // static method call method = person.getClass().getMethod(“beta”,int.class); String out = (String) …

Java Reflection 5 Class Metot’u Cagirmak(invoke) Read More »

Java Reflection 4 Class Degiskenini Degistirmek

public class Person { public int age; public static int weight; } Person person = new Person(); try { // Non static variable with object Person.class.getField(“age”).setInt(person, 15); // Setting static variable Person.class.getField(“weight”).setInt(null, 3); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); …

Java Reflection 4 Class Degiskenini Degistirmek Read More »

Java Reflection 1 Class Değişkenlerini 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; } …

Java Reflection 1 Class Değişkenlerini Listelemek Read More »