Ambiguous method call Both assertEquals(Object, Object) in Assert and assertEquals(double, double) in Assert match:

java123999 :

I am getting the following error:

Both assertEquals(Object, Object) in Assert and assertEquals(double, double) in Assert match

For this line of code in my Junit tests, note that getScore() returns a double:

assertEquals(2.5, person.getScore());

This is my assert import:

import static org.junit.Assert.*;

What is causing this and how can I fix this?

Bechyňák Petr :

I guess your getScore() returns Double, not double. Therefore compiler is confused: Should he convert both arguments to Object, or should he convert only the Double to double?

    double a = 2.0;
    Double b = 2.0;
    // assertEquals(a,b); // fails to compile
    // the compiler is confused whether to use
    assertEquals((Object) a,(Object) b); // OK
    // or
    assertEquals(a,(double) b); // OK

Anyway, I would set the method to return primitive type double.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=426196&siteId=1