public
class
FieldReflactTest{
public
static
final
String a=
"test"
;
protected
int
b;
private
int
c;
String d;
public
static
void
main(String[] args){
Field[] fields=FieldReflactTest.
class
.getDeclaredFields();
for
(Field field:fields){
String descriptor=Modifier.toString(field.getModifiers());
//获得其属性的修饰
descriptor=descriptor.equals(
""
)==
true
?
""
:descriptor+
" "
;
System.out.println(descriptor+field.getName()+
"="
+field.get(
new
FieldReflactTest()));
}
}
}
时间: 2024-10-14 22:45:02