Generic records produce code with `rawtypes` and `unchecked` warnings
daveschoutens opened this issue · comments
At work, we are making great use of your library. Thanks!
That said, we introduced our first record using generics the other day, and found the generated Builder class to suffer from a few javac warnings, namely unchecked
and rawtypes
. We have a very low tolerance for compiler warnings, so this blocks us from using @RecordBuilder for these types.
We use JDK 17
Minimal example:
@RecordBuilder
public record Foo<T>(List<T> items) {}
Problematic generated code snippets:
// FooBuilder
@Generated("io.soabase.recordbuilder.core.RecordBuilder")
@Override
public boolean equals(Object o) {
return (this == o) || ((o instanceof FooBuilder r) // <- javac flags [rawtypes] warning here
&& Objects.equals(items, r.items));
}
// ...
@Generated("io.soabase.recordbuilder.core.RecordBuilder")
default FooBuilder<T> with() {
return new FooBuilder(items()); // <- javac flags [rawtypes] and [unchecked] warnings here
}
It would be ideal if equals()
could appease the compiler with (o instanceof FooBuilder<?> r)
and with()
could similarly with new FooBuilder<>(items())
.
Barring that, perhaps a @SuppressWarnings({"unchecked","rawtypes"})
on these methods or on the class.