Java – How to safely remove a method and how do I know if it is not being used by reflection?

How to safely remove a method and how do I know if it is not being used by reflection?… here is a solution to the problem.

How to safely remove a method and how do I know if it is not being used by reflection?

I

know there’s not a method referenced in my Android project, but I’ve seen some reflection here and there (its legacy code, I’m not familiar with it).
How do I determine if it’s not being called by reflection somewhere so that I can safely remove it?

Solution

In a completely general setup, I don’t think this is possible. You need to check something similar

Class.forName("some.pkg.here.and.SomeClass");

For

Class.forName(packageName + "." + className);

The use of reflections can also be hidden behind libraries.

It’s much easier if you have a test. Just delete it and run the test.

You can also add logging to legacy methods that you wish to remove and check from there.

Related Problems and Solutions