简体   繁体   中英

assertEquals problems (object object) (long long)

Interval<Integer> interval1 = Intervals.open(3, 6);

Here 3 is the lower bound, and 6 is the upper bound.

assertEquals(interval1.lowerBound(), 3);

After writing the test, there is a red underline saying:

ambiguous method call.Both assertEquals(object, object) assertEquals(long, long)

The problem is that you're calling assertEquals with a Long and an int , so the compiler can't tell whether you want assertEquals(long, long) (autounboxing the Long ) or assertEquals(Object, Object) (autoboxing the int ).

To fix this, you need to handle the unboxing or boxing yourself, by writing either this:

assertEquals(3L, interval1.lowerBound().longValue());

or this:

assertEquals(Long.valueOf(3L), interval1.lowerBound());

(Incidentally, note that I swapped the order of the two arguments for you. assertEquals expects the first argument to be the expected value and the second to be the actual value. This doesn't affect the assertion itself, but it affects the exception-message that's generated when the assertion fails.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM