-
Notifications
You must be signed in to change notification settings - Fork 150
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
Introduce Self
interface
#801
Comments
jenetics
added a commit
that referenced
this issue
Oct 13, 2021
jenetics
added a commit
that referenced
this issue
Oct 13, 2021
jenetics
added a commit
that referenced
this issue
Oct 19, 2021
jenetics
added a commit
that referenced
this issue
Oct 19, 2021
jenetics
added a commit
that referenced
this issue
Oct 19, 2021
…interface #801: Add 'Self' interface.
Merged into r7.0.0 branch. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some classes/interface in the library are using recursive generic types, as a possibility to model a self type. Similar to the abstract
Enum<E extends Enum<E>>
type in the JDK. TheGene
type is such a type.The purpose of this, as illustrated in the code snippet above, is to avoid casts when working with the interface definition alone and creating new instances of the concrete implemented type
G
. In a proper implementation, it is save to castthis
toG
. But this is a very implicit convention. Nobody prevents you from creating the following class.Instead of the correct declaration of
To make the intention more explicit, the following interface is added
It is still possible to create invalid implementations, but the interface allows to make the intended purpose more explicit, also via the Javadoc of the interface.
The text was updated successfully, but these errors were encountered: