简体   繁体   English

Java:仅编译来自另一个类的选定方法

[英]Java: Compile only selected methods from another class

If my java class "UserClass" depends on another class "UsedClass"(provided as a library jar). 如果我的java类“UserClass”依赖于另一个类“UsedClass”(作为库jar提供)。 If the "UsedClass" has 26 methods(lets say A - Z). 如果“UsedClass”有26种方法(比方说A-Z)。 But my "UserClass" needs only methods from(lets say A to D, assuming they dont internally call any methods other than A to D). 但是我的“UserClass”只需要方法(比如A到D,假设他们不在内部调用除A到D之外的任何方法)。 When I build the "UserClass", Is there any way to prevent unused methods(example E to Z) from "UsedClass" from being shipped in my application(which may increase size of distributable/memory consumption while execution). 当我构建“UserClass”时,有没有办法阻止来自“UsedClass”的未使用的方法(例如E到Z)在我的应用程序中运送(这可能会增加执行时可分发/内存消耗的大小)。

Don't do premature optimisation, in most cases it is the libraries who adding size to your project. 不要进行过早优化,在大多数情况下,是为项目添加大小的库。 If your methods not used any there then just delete then. 如果您的方法没有使用那么只需删除。 If the are used by some other unrelated code then you better split your code into modules so you can use them in a different combination. 如果某些其他不相关的代码使用它们,那么您最好将代码拆分为模块,以便可以在不同的组合中使用它们。 As I already said your code(the code you created) will be the smallest part of your final application. 正如我已经说过的,您的代码(您创建的代码)将是最终应用程序的最小部分。 If you still insist that you want to conditionally compile methods, then I will say it isn't possible with standard tools. 如果您仍然坚持要有条件地编译方法,那么我会说使用标准工具是不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM