Allow access modifier override from more restrictive to less restrictive #5572
Unanswered
0x0737
asked this question in
Language Ideas
Replies: 1 comment 4 replies
-
|
If the base method takes a more restrictive type (protected nested type) as parameter/return, then the override can't change the access modifier. Since we have solved covariant return, and Java/Kotlin solved this issue, I'd expect it to be straight forward. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Currently it is not possible to give an overriden method a less restrictive access modifier.
A workaround exists, where you declare a "proxy" method with a different name and make it invoke the original method, but it adds clutter to the code. So, I propose to allow overriding access modifiers from more restrictive to less restrictive:
Obviously, this wouldn't work if the base method was private.
Note: the code like above is allowed in Kotlin and Java (and probably other languages too).
Beta Was this translation helpful? Give feedback.
All reactions