this.getClass()。getFields()。length;总是返回0 [英] this.getClass().getFields().length; always returns 0

查看:679
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆