java.lang.IncompatibleClassChangeError 的原因是什么? [英] What causes java.lang.IncompatibleClassChangeError?

查看:45
本文介绍了java.lang.IncompatibleClassChangeError 的原因是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Java 库打包为 JAR,当我尝试从中调用方法时,它抛出了许多 java.lang.IncompatibleClassChangeError.这些错误似乎是随机出现的.什么类型的问题可能导致此错误?

I'm packaging a Java library as a JAR, and it's throwing many java.lang.IncompatibleClassChangeErrors when I try to invoke methods from it. These errors seem to appear at random. What kinds of problems could be causing this error?

推荐答案

这意味着您在没有重新编译客户端代码的情况下对库进行了一些不兼容的二进制更改.Java 语言规范 §13 详细介绍了所有此类更改,最显着的是,将非static 非私有字段/方法更改为static,反之亦然.

This means that you have made some incompatible binary changes to the library without recompiling the client code. Java Language Specification §13 details all such changes, most prominently, changing non-static non-private fields/methods to be static or vice versa.

针对新库重新编译客户端代码,您应该很高兴.

Recompile the client code against the new library, and you should be good to go.

更新:如果您发布公共库,则应尽可能避免进行不兼容的二进制更改,以保留所谓的二进制向后兼容性".理想情况下,单独更新依赖 jar 不应破坏应用程序或构建.如果您确实必须破坏二进制向后兼容性,建议增加主要版本号(例如从 1.xy 到 2.0.0) 在发布更改之前.

UPDATE: If you publish a public library, you should avoid making incompatible binary changes as much as possible to preserve what's known as "binary backward compatibility". Updating dependency jars alone ideally shouldn't break the application or the build. If you do have to break binary backward compatibility, it's recommended to increase the major version number (e.g. from 1.x.y to 2.0.0) before releasing the change.

这篇关于java.lang.IncompatibleClassChangeError 的原因是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆