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

Incorrect example of narrowing from Collection to RandomAccesss #11

Closed
elizarov opened this issue Apr 19, 2023 · 0 comments
Closed

Incorrect example of narrowing from Collection to RandomAccesss #11

elizarov opened this issue Apr 19, 2023 · 0 comments

Comments

@elizarov
Copy link
Contributor

From https://kotlinlang.org/docs/jvm-api-guidelines-backward-compatibility.html#don-t-make-return-types-narrower

For example, sometimes you realize that you need index access to the elements of your collection and want to change the return type from Collection to RandomAccess.

However, RandomAccess is a marker interface, not a subtype of Collection, so this is an incorrect example.

Also, the section name "Don't make return types narrower" leads reader to an implicit assumption that "making return types wider" is somehow a good thing. It clearly needs a clarification that narrowing, unlike widening, is mostly source-compatible, so it is tempting to do, yet should not be done.

asm0dey added a commit that referenced this issue Apr 21, 2023
I have changed the example from `RandomAccess` to `List` and change the wording a bit to clarify the point on the widening
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

1 participant