I have an interface Schema, and another called SchemaParser.
SimpleSchemaParser implements SchemaParser and SimpleSchema implements Schema.
SimpleSchemaParser has a method parseSchema() which returns a Schema. This way, SimpleSchemaParser.parseSchema() would return a Schema object. But I know that SimpleSchemaParser would always return a SimpleSchema. How should I change my design to make this apparent, rather than always having to cast the result to SimpleSchema? Should I go for generics in this case?
You can indeed use generics, but they’re not required:
A slightly broader question is: why do you care which implementation of schema is returned? Are there methods that only exist on
SimpleSchema? Can these move up to the interfaceSchema?