this.getClass().getFields().length;总是返回 0 [英] this.getClass().getFields().length; always returns 0
本文介绍了this.getClass().getFields().length;总是返回 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取特定类中的字段数.但是我使用的技术不起作用并且总是返回 0:
I am trying to get the number of fields in a particular class. However the technique I am using is not working and always returns 0:
this.getClass().getFields().length;
如何获取特定类的字段数?
How do I get the field count of a particular class?
推荐答案
使用 this.getClass().getDeclaredFields().length
getFields
方法用于可访问的公共字段 - 请参阅 文档.
Use this.getClass().getDeclaredFields().length
The getFields
method is for accessible public fields - see documentation.
这篇关于this.getClass().getFields().length;总是返回 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文