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

Validators contravariance #65

Open
javier-godoy opened this issue Nov 12, 2022 · 0 comments
Open

Validators contravariance #65

javier-godoy opened this issue Nov 12, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@javier-godoy
Copy link
Member

javier-godoy commented Nov 12, 2022

ValidatorSupport.getValidators() should return a List<Validator<? super T>> instead of List<Validator<T>>, because PECS.

https://github.com/AppJars/commons-backend/blob/ca5a44fea72cec4a41f3b5c240bd8da590a43b0c/commons-model/src/main/java/com/appjars/saturn/validation/ValidationSupport.java#L27

image
(Picture courtesy: Andrey Tyukin CC-BY-SA)

For instance, if MyEntity implements HasFoo and FooValidator implements Validator<HasFoo>, then MyEntityService can implement getValidators() as:

	public List<Validator<? super MyEntity>> getValidators() {
		return List.of(new FooValidator());
	}

(which makes sense because FooValidator is able to validate any Foo, including my entity)

@mlopezFC mlopezFC added the bug Something isn't working label Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants