Home Get only properties count for java class

Get only properties count for java class

tkrz
1#
tkrz Published in 2017-12-07 11:16:10Z
 Ok, so i have tried to get count of properties for class. I have seen two related questions, but they are not quite answering this. question one question two problem with those two is, that SomeClass.class.getDeclaredFields().length  and SomeClass.class.getDeclaredMethods().length  are not quite return what i would expect them to. I got sample class: SomeClass { public static final int ONE = 1, TWO = 2, THREE = 3; public static int someMethodOne(){} public static int someMethodTwo(){} }  Declared fields return 5 which according to this is wrong, and should be 3. Declared methods does not help either, because it returns 3, while there are only 2 declared methods. What is wrong with this? Edit: trying to do this with Java 8 & Android Studio
Stefan
2#
 I get 3 and 2 as expected when I run the code below. If you get other values, you could also print the names of the fields and the methods (see below). public class SomeClassChecker { public static void main(String[] args) { System.out.println(SomeClass.class.getDeclaredFields().length); System.out.println(SomeClass.class.getDeclaredMethods().length); for (Field field : SomeClass.class.getDeclaredFields()) { System.out.println("field: " + field.getName()); } for (Method method : SomeClass.class.getDeclaredMethods()) { System.out.println("method: " + method.getName()); } } }  Java 8 & Eclipse. I get this (expected) output: 3 2 field: ONE field: TWO field: THREE method: someMethodOne method: someMethodTwo