Error when using LogManager (l4j2) with Java 8 (java.lang.reflect.AnnotatedElement cannot be resolved)

后端 未结 5 702
南旧
南旧 2020-11-22 12:14

I just encountered a strange error when switching the JDK version of a new Project of mine from 7u45 to 8u20. A harmless LogManager declaration at the beginning of my class

5条回答
  •  忘了有多久
    2020-11-22 13:05

    When using JDK 8 and an IDE (or any other code processing tool/framework) with its own compiler, like Eclipse, you have to update the tool to a version with Java 8 support, even if you are not using the newer Java 8 features.

    The reason is that the compiler must be able to load the newer class files of the JRE in order to compile your software which references these classes.

    Sometimes you can get away with an older compiler when it ignores the newer version number of the class files. But some types will confuse older class file parsers as they use new features, notably AnnotatedElement, which now has default methods, and Map.Entry, an interface which now has static methods.

    It seems that Eclipse does not make a difference between references for which no class file could be found and class files it failed to read when saying “«classname» cannot be resolved”.

    The same applies to all tools and frameworks using ECJ as embedded compiler.

提交回复
热议问题