var cls = Person.class;
// System.out.println(Arrays.toString(cls.getDeclaredMethods()));
for (Method mthd : cls.getDeclaredMethods()) {
if (mthd.getReturnType() == void.class) {
if (mthd.getName().endsWith("Name")) {
mthd.invoke(p, name);
}
if (mthd.getName().endsWith("Age")) {
mthd.invoke(p, age);
System.out.println(mthd);
// Arrays.stream(cls.getDeclaredMethods()).
// filter(mthd -> mthd.getReturnType() == void.class).
// forEach((mthd -> mthd.getName().endsWith("Name") ? mthd.invoke(p, name) : mthd.invoke(p, age)));
Sign in to make a reply
张_典博
var cls = Person.class;
// System.out.println(Arrays.toString(cls.getDeclaredMethods()));
for (Method mthd : cls.getDeclaredMethods()) {
if (mthd.getReturnType() == void.class) {
if (mthd.getName().endsWith("Name")) {
mthd.invoke(p, name);
}
if (mthd.getName().endsWith("Age")) {
mthd.invoke(p, age);
}
System.out.println(mthd);
}
}
// Arrays.stream(cls.getDeclaredMethods()).
// filter(mthd -> mthd.getReturnType() == void.class).
// forEach((mthd -> mthd.getName().endsWith("Name") ? mthd.invoke(p, name) : mthd.invoke(p, age)));