aws / event-ruler

Event Ruler is a Java library that allows matching many thousands of Events per second to any number of expressive and sophisticated rules.
Apache License 2.0
570 stars 65 forks source link

Cannot create GenericMachine using builder() for anything but Object without compiler warnings/errors #174

Closed youngm closed 3 months ago

youngm commented 3 months ago

I'd like to create a GenericMachine for Integer and I cannot do it without unsafe casts and compiler warnings.

To Reproduce

Try these various ways to create a GenericMachine without a warning or error. They all fail.

GenericMachine<Integer> try1Deprecated = new GenericMachine<Integer>();
GenericMachine<Integer> try1Raw = GenericMachine.builder().build();
GenericMachine<Integer> try2Raw =
    GenericMachine.builder().<GenericMachine<Integer>>build();
GenericMachine<Integer> try3NotVisible =
    new GenericMachine.Builder<GenericMachine<Integer>>().build();

Expected behavior

Should be able to create a GenericMachine for a given type without a compiler warning.

Perhaps the build() method could accept a generic parameter?

Environment:

Java 17

Additional context

Sure, GenericMachine works but why make it generic if there isn't a clean way to make an instance of any other type?

baldawar commented 3 months ago