0
0

More than 1 year has passed since last update.

エラー対処:References to interface static methods are allowed only at source level 1.8 or above Java(1610613404)

Last updated at Posted at 2023-02-10

エラー対処の備忘録です。

MavenプロジェクトでJavaのコードを書き始めた時に、次のようなエラーが出ました。

References to interface static methods are allowed only at source level 1.8 or above Java(1610613404)

image.png

原因

原因はmaven-compiler-pluginの設定でソースのjavaバージョンを指定していなかったためでした。(デフォルトでは1.7でした1)

javaでインターフェースにstaticメソッドを定義できるようになったのはバージョン1.8からなので、そのメソッドを使うためにはコンパイラにもそのバージョン以上を使うことを指定しないとだめということですね。

修正内容

pom.xmlに追加していたmaven-compiler-pluginに、以下のように1.8以上のjavaのバージョンを指定するとエラーがなくなりました。

pom.xml
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
          <configuration>
            <source>17</source>
            <target>17</target>
          </configuration>
        </plugin>

(参考 https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

  1. https://maven.apache.org/plugins/maven-compiler-plugin/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0