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

Add @Covariant and @Contravariant annotations #20

Open
Glavo opened this issue Dec 14, 2019 · 4 comments
Open

Add @Covariant and @Contravariant annotations #20

Glavo opened this issue Dec 14, 2019 · 4 comments

Comments

@Glavo
Copy link

Glavo commented Dec 14, 2019

As a library developer, I want to be able to add some annotations to mark the variance of the type parameters of a class. IDE can give the following hint based on this annotation:

  • Report a warning when contravariant type parameter T is used as a function parameter type
  • Report a warning when covariant type parameter T is used as a function return type
  • For function parameter types, prompt user to use Function<? extends T, ? super U> (take java.util.function.Function as an example) instead of Function<T, U>

And the jvm-based language can choose to understand this annotation (e.g. kotlin can understand class C<@Covariant T> as class C<out T>. This is convenient for developers to provide Kotlin-friendly APIs using pure Java.

@amaembo
Copy link
Collaborator

amaembo commented Dec 15, 2019

See also https://openjdk.java.net/jeps/300

@Glavo
Copy link
Author

Glavo commented Dec 15, 2019

This JEP has not been updated in three years, and I am confused about its status and have no confidence in its delivery in the next few years. Even if Java 17 can implement this feature, many libraries still have to stay in Java 8 or even Java 5 for a long time. I think it is very meaningful to add corresponding annotations.

@Glavo
Copy link
Author

Glavo commented Aug 4, 2021

Do you have any ideas about them now?

@amaembo
Copy link
Collaborator

amaembo commented Aug 4, 2021

This issue didn't gain a lot of interest, so for now, we don't consider this feature request as a priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants