groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (JIRA)" <>
Subject [jira] [Commented] (GROOVY-8722) final modifier for non-abstract methods in traits is ignored
Date Wed, 01 Aug 2018 10:20:00 GMT


Paul King commented on GROOVY-8722:

You are correct that currently final is ignored/not supported and it isn't mentioned in the
docs. We should definitely add something in the docs and/or a compiler error message.

While not an exact equivalent, it is worth reading the "api evolution" rationale about why
Java doesn't allow methods in interfaces to be final:

Now, traits are a slightly more powerful beast and you could make an argument about them having
a different semantics here, but similar arguments still do apply. It is worth going back to
the intent of traits to consider whether supporting final would make sense. Currently, a method
in a trait provides a default implementation that can be overridden. So, if you provide your
own implementation does that mean you are overriding the trait method or just not taking advantage
of a default implementation?

If you multiply inherit a method from multiple traits, the last one "inherited" wins. So if
an earlier one is final, should I give a warning or just realise that I am not taking that
implementation? And, if I am going to ignore an earlier final method in that case, does it
also make sense to ignore such "inherited " methods if I provide my own implementation?
Probably the only definition that would make sense would be that if you inherit one final
method you can't inherit any others (with the same signature) nor override. If we did support
final, that is probably the definition that I would advocate but we need to appreciate that
it would be the definition that impacted api evolution the most.

> final modifier for non-abstract methods in traits is ignored
> ------------------------------------------------------------
>                 Key: GROOVY-8722
>                 URL:
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler, Documentation
>    Affects Versions: 2.4.15, 2.5.1
>            Reporter: Dmytro Buryak
>            Priority: Major
>              Labels: documentation
> {{When use {color:#707070}final{color} modifier in trait non-abstract method signature,
>  * {{compiler successfully compiles trait and class that implements it}}
>  * {{final method of trait may be overridden in class that implements trait}}
>  * {{if class implements trait and doesn't override trait final method, then this method
is available as non-final method in class}}
>  * {{documentation says absolutely nothing about this}}
> {{In other words, {color:#707070}final{color} modifier is ignored in trait methods: code
works the same with or without it. Even if this behavior is expected, there's nothing about
it in the documentation.}}
> {{Here's simple example gradle groovy project to demonstrate the issue: [|]}}

This message was sent by Atlassian JIRA

View raw message