Java error: Found interface … but class was expected

后端 未结 5 2153
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 00:55

I am getting a strange runtime error from my code:

\"Found interface [SomeInterface] but class was expected\"

How can this happen? How can an i

5条回答
  •  我寻月下人不归
    2021-02-05 01:34

    This happened to me when i was running a maven build.

    From what i could gather (as well as from Jared's answer) as the reason was that - there were two versions of the same 3rd party jar specified in my effective pom.xml. One version was coming in as a transitive dependency and the other was specified by me in my local pom.xml.

    So at compile time, it was referring to the old version and at runtime it was referring to the new version.

    I removed the version specified in my local pom.xml and it worked.

    Of course, the 3rd party had broken backward-compatibility between their versions and changed a class to an interface or vice-versa. But they are free to do so.

提交回复
热议问题