0

I have a value class with generic type:

class TestValue<T> {
    TestValue(T value) {
    }
}

And a method that expects TestValue with a specific SomeObject type:

public void setValue(TestValue<SomeObject> value) { }

Is there a way to show a compiler error when calling this method with a value that is not of SomeObject type?

eg show a compiler error when calling this with Double instead of SomeObject

TestValue t = new TestValue(1d);
setValue(t);

^^ this should show an error

tonisives
  • 1,962
  • 1
  • 18
  • 17

1 Answers1

0

In IntelliJ the compiler actually finds these issues, but they are shown as warnings. You can edit the inspection settings and set Java | Compiler issues | Unchecked warning to error, then it is show as error.

enter image description here

tonisives
  • 1,962
  • 1
  • 18
  • 17