/**
* @author lautturi.com
* Java example: java check if there is public property in class
*/
import java.util.*;
class Person{
public String name;
public int age;
}
public class Lautturi {
public static void main(String[] args) {
Person p = new Person();
if( Arrays.stream(p.getClass().getFields())
.anyMatch(f -> f.getName().equals("name")))
System.out.println("The Person class has a field named name ");
}
}
output:
The Person class has a field named name