Java Reflection: Getting fields and methods in declaration order

前端 未结 6 960
不知归路
不知归路 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:07

    You won't be able to get the information from the class file. As Adam said in an answer to the refrenced other question:

    The elements in the array returned are not sorted and are not in any particular order.

    And "no order" includes "no declaration order".

    I once used a Java source file parser to get input data for code generators. And this way you'll have fields and methods in declaration order.

提交回复
热议问题