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

Verify Interface Compliance with Generic support #209

Open
agtabesh opened this issue Feb 19, 2024 · 0 comments
Open

Verify Interface Compliance with Generic support #209

agtabesh opened this issue Feb 19, 2024 · 0 comments

Comments

@agtabesh
Copy link

agtabesh commented Feb 19, 2024

Using var _ http.Handler = (*Handler)(nil) is a great idea to make sure that Handler implements http.Handler properly.
What if both the interface and the struct using generic?

For example:

type Score interface {
	int64 | float64
}

type ScoreCalculator[T Score] interface {
	Add(score T) T
}

type SampleAlgorithm[T Score] struct {}
func (s *SampleAlgorithm[T]) Add(score T) T {
	// do some manipulation
	return score
}

Should I use both types for verifying compliance?

var _ ScoreCalculator[int64] = (*SampleAlgorithm[int64])(nil)
var _ ScoreCalculator[float64] = (*SampleAlgorithm[float64])(nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant