Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should ClassifierCompositeItemWriter use covariance (extends "keyword" instead "super") in the output type of classifier property? #4592

Open
alvarofvr opened this issue May 13, 2024 · 0 comments
Labels
status: waiting-for-triage Issues that we did not analyse yet type: feature

Comments

@alvarofvr
Copy link

alvarofvr commented May 13, 2024

Expected Behavior
The ClassifierCompositeItemWriter should use covariance for classify the items. In the class the classifier property should be defined with an output type of ItemWriter<? extends T>. This way I can use a SubclassClassifier to classify the items.

Current Behavior

ClassifierCompositeItemWriter use contravariance for classify the items. In the class the classifier property is defined with an output type of ItemWriter<? super T>:

public class ClassifierCompositeItemWriter<T> implements ItemWriter<T> {

	private Classifier<T, ItemWriter<? super T>> classifier = new ClassifierSupport<>(null);

Context

I want to classify 2 type of items : PetToCreate extends PetAction{} and PetToUpdate extends PetAction{} and delegate to the corresponding writers: CreatePetWriter implements ItemWriter<PetToCreate> or UpdatePetWriter implements ItemWriter<PetToUpdate>.

So I use a SubclassClassifier:

var typeMap = Map.of(
          PetToCreate.class, createPetWriter,
          PetToUpdate.class, updatePetWriter
);
SubclassClassifier<PetAction, ItemWriter<? extends PetAction>> petActionItemWriterSubclassClassifier = new SubclassClassifier<>(typeMap, null);

But the type checking fails:
image

Can someone explain to me the motivation behind this choice, shouldn't it be possible to achieve it?

I also opened a question on StackOverflow: https://stackoverflow.com/questions/78459916/why-classifiercompositeitemwriter-use-contravariance-for-classify-the-items

@alvarofvr alvarofvr added status: waiting-for-triage Issues that we did not analyse yet type: feature labels May 13, 2024
@alvarofvr alvarofvr changed the title Should ClassifierCompositeItemWriter use covariance (extends "keyword" instead "super") in the output type? Should ClassifierCompositeItemWriter use covariance (extends "keyword" instead "super") in the output type of classifier property? May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage Issues that we did not analyse yet type: feature
Projects
None yet
Development

No branches or pull requests

1 participant