1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【JUnit5】「assertEqualsの参照はあいまいです」への対処

Last updated at Posted at 2019-10-13

問題

以下のように、片方がプリミティブ型、片方がオブジェクト型な状態でorg.junit.jupiter.api.Assertions.assertEqualsを呼び出すと「assertEqualsの参照はあいまいです org.junit.jupiter.api.Assertionsのメソッド assertEquals(java.lang.Object,java.lang.Object)とorg.junit.jupiter.api.Assertionsのメソッド assertEquals(int,int)の両方が一致します」としてコンパイルエラーになります。

assertEquals(1, (Integer) 1);

対処

どちらかをキャストしてやれば大丈夫です。
基本的にプリミティブ型にキャストしてやるのがいいと思います。

assertEquals(1, (int) ((Integer) 1));
1
3
1

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
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?