Determine Which Parameter in Constructor was used to Set a Specific Field in Class?

元气小坏坏 提交于 2020-03-04 18:21:27

问题


I'm working on developing a custom Java object persistence framework as I recently discussed in this question.

One issue I am trying to solve is to force uniform annotation values in constructor parameter and method.

Is it possible to know which parameter in constructor was used to set a specific field in class via reflection? For example, if constructor contains parameter String textXYZ and class contains field String textABC and in constructor I do: textABC = textXYZ (so field/parameter have different names). Is it possible to know that the field textABC is associated with the constructor parameter textXYZ via reflection?

This would allow me to set annotation just on field and then deduce annotation value of parameter or vice versa..

Thanks

来源:https://stackoverflow.com/questions/60512364/determine-which-parameter-in-constructor-was-used-to-set-a-specific-field-in-cla

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!