How do I implement this properly? A question that involves Java generics, inheritance, and consumers
I’m trying to implement a sort-of Builder pattern that takes in raw data, and depending on what needs to be built, gets a predefined schema with a set of Consumers, specifically targeted for what needs to be built. The base class Builder handles all the logic of deciding what consumers on the Schema need to be called (with the accept method of Consumer). Sub classes of Builder implement their own methods (on top of the ‘standard’ ones available in Builder) and have their own Schema defined. The custom Schemas with their sets of available Consumers are how Builder builds what needs to be built from the raw data. Here’s the simplified code with Schema’s just having one Consumer ‘reference’ to the custom builders. I’m having issues with the combination of inheritance, typing, and generics. The BiConsumer.accept()
method in Builder.build()
does not like how it’s being called. I can’f figure out how to fix the generic typing/identifiers/wild-cards issues shown by this error: