gpt4 book ai didi

java - getMethods 是否可以按顺序使用反射?

转载 作者:搜寻专家 更新时间:2023-10-31 19:58:02 24 4
gpt4 key购买 nike

<分区>

Possible Duplicates:
Java Reflection: Getting fields and methods in declaration order
Java. Get declared methods in order they apear in source code

假设我有这门课

是否可以按顺序使用 getter 方法?

public class ClassA {

private String name;
private Integer number;
private Boolean bool;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Integer getNumber() {
return number;
}

public void setNumber(Integer number) {
this.number = number;
}

public Boolean getBool() {
return bool;
}

public void setBool(Boolean bool) {
this.bool = bool;
}

我试过了..

for (Method method : ClassA.class.getDeclaredMethods()) {
if (!(method.getReturnType().toString().equals("void"))) {
method.invoke(obj, new Object[0])));
}
}

我从文档中得到的

...The elements in array returned are not sorted and are not in any particular order...

那么..就是这样吗?是否存在一些替代方案,或者我只需要实现一些东西?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com