简体   繁体   English

我需要在这里重新构建Java吗?

[英]Do I need a rebuild for Java here?

I have a ClassA that is being used my many components and libraries in various areas of a project. 我有一个ClassA ,它在项目的各个领域都在使用我的许多组件和库。
Now I need to add an extra member to this class but since it will not be needed/used by other areas it does not feel proper to extend the class. 现在,我需要为该类添加一个额外的成员,但是由于其他领域将不需要/使用它,因此extend该类并不适合。
If I add the member to ClassA instead of extending would I have any issues? 如果我将成员添加到ClassA而不是extending是否会遇到任何问题? Would everything need to be rebuild? 一切都需要重建吗?

Adding a new member preserves binary compatibility, see also Chapter 13. Binary Compatibility of the Java Language specification. 添加新成员将保留二进制兼容性,另请参见第13章 。Java语言规范的二进制兼容性

Obviously you need to rebuild the modified class, but not classes which are using the modified one. 显然,您需要重建修改后的类,而不是重建使用修改后的类的类。

Unless your existing contacts and interactions between ClassA and other classes BREAK, there should be no issue. 除非您现有的ClassA与其他班级之间的联系和互动BREAK,否则就不会有问题。 But if you change signature of a method that is used by other classes you could get a runtime error while locating the old version of method as it does not exist anymore. 但是,如果更改其他类使用的方法的签名,则在定位该方法的旧版本时会遇到运行时错误,因为该方法不再存在。

If you change your Class A, obviously a rebuild is necessary. 如果您更改A类,则显然需要重新构建。 To minimize the impact you can extend the class A and use the subclass for your work. 为了最大程度地减少影响,您可以扩展A类并在工作中使用子类。 The other components and libraries will continue to keep using your Class A, while your code should now refer to the sublcass which has the added member. 其他组件和库将继续使用您的A类,而您的代码现在应引用具有已添加成员的sublcass。

Again, it depends on how you define your objects. 同样,这取决于您如何定义对象。

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

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