You can take a look at the obfuscation tools, they can also often delete dead code, that is, classes, methods and the like that are not referenced anywhere in the code.
For example, you can use ProGuard .
From the documentation:
ProGuard is a free Java file compression tool, optimizer, obfuscater and preverifier. It detects and removes unused classes, fields, methods, and attributes. It optimizes bytecode and removes unused instructions. It renames the rest of the classes, fields, and methods using short, meaningless names. Finally, it predefines the processed code for Java 6 or for Java Micro Edition.
You can customize it to take only a drying step. In your case, you should use the -keep option to tell ProGuard that you want to use class B, and end up with B and C, as you describe. This may not be exactly what you want, since ProGuard will also remove unused methods, etc., by changing the classes in your JAR file (I don’t know a single option to disable this). In addition, you need to tell ProGuard that it does not perform any other actions that it usually performs, such as obfuscation.
If ProGuard does not meet your needs, you can look for other tools for obfuscation and / or reduction. Hope this helps, and good luck!
source share