I'm trying out the nice checker-framework on my project, thanks for all the work!
It seems to work fine, but I am running into one problem where I'm wondering how I should use this. I have tried to provide a simple example below that illustrates what I'm running into.
The compiler gives me the following:
OptionalTest.java:24: error: [assignment] incompatible types in assignment.
Optional<@m Integer> myOptionalMeters = resolveInt().map(this::calculate);
^
found : @UnknownUnits Optional<@UnknownUnits Integer>
required: @UnknownUnits Optional<@m Integer>
Do you have any advice on how to go about this? Is this a case where I should be suppressing warnings? Or is there a better way to deal with this?
It feels like annotations get lost in the generics used in the map() function. Is there anyone here that can shed more light on that?
Thanks a lot!
import static org.assertj.core.api.Assertions.*;
import java.util.*;
import org.checkerframework.checker.units.qual.*;
import org.junit.Test;
public class OptionalTest
{
@SuppressWarnings("units")
public static final @m int m = 1;
Optional<Integer> resolveInt()
{
return Optional.of(5);
}
@m int calculate(int aValue)
{
return aValue * m;
}
@Test
public void reproduce()
{
Optional<@m Integer> myOptionalMeters = resolveInt().map(this::calculate);
assertThat(myOptionalMeters).isPresent();
}
}