Java Reflection: Getting fields and methods in declaration order

前端 未结 6 972
不知归路
不知归路 2020-11-29 07:27

Is there any way to get a classes declared fields (and methods) in the order of declaration using reflection? According to the documentation, the ordering of Methods and Fie

6条回答
  •  忘掉有多难
    2020-11-29 08:04

    I had this as an isolated problem, look at

    https://github.com/wmacevoy/kiss/blob/master/src/main/java/kiss/util/Reflect.java

    and the method

    public static Method[] getDeclaredMethodsInOrder(Class clazz)

    It gets the order by looking at the bytecode of the class. If you just want to use the libray, is would be kiss.util.Reflect.getDeclaredMethodsInOrder(Test.class)

提交回复
热议问题