Java Reflection and the pain in Refactoring

后端 未结 9 1670
清歌不尽
清歌不尽 2021-02-08 14:25

Java Reflection provides a mechanism to introspect an Object at runtime. No second thoughts, this is a great feature, but it breaks all the Refactoring conventions!

Ther

9条回答
  •  难免孤独
    2021-02-08 15:01

    Modern IDE's have the feature that when renaming a class, they will search for the fully qualified name in, for example, your xml files to try and rename any references you might have in those. Don't think it solves the problem - very often you don't absolutely reference class names.

    Also, that is why particular care and consideration must be exercised before you use it in your own code.

    But this problem with reflection is why using annotations is becoming more popular. The problem is reduced when using annotations.

    But let me say, as the previous post rightly points out, if you don't have a good safety net of unit tests, any kind of refactoring, whether you use a lot of reflection or not, is dangerous.

提交回复
热议问题