You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/06/11 19:19:00 UTC

[jira] [Commented] (GROOVY-10133) Inconsistent method selection for [Bb]oolean properties

    [ https://issues.apache.org/jira/browse/GROOVY-10133?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17361997#comment-17361997 ] 

Eric Milles commented on GROOVY-10133:
--------------------------------------

So it would seem the safest choice is to fix the "isser" preference for subclasses.  "getter" is the preferred accessor in more cases.

> Inconsistent method selection for [Bb]oolean properties
> -------------------------------------------------------
>
>                 Key: GROOVY-10133
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10133
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.5.14, 3.0.8
>            Reporter: Eric Milles
>            Priority: Major
>
> In addition to the issues noted in GROOVY-5245, GROOVY-6097, GROOVY-9382 and GROOVY-9851, there are inconsistencies when both "get" and "is" options are available for boolean properties.
> Consider the following:
> {code:groovy}
> class C {
>   boolean isX() { true }
>   boolean getX() { false }
>   void test() {
>     println x // "get"
>     println this.x // "get"
>   }
> }
> new C().test()
> println new C().x // "get"
> class D extends C {
>   void test2() {
>     println x // "is"
>     println this.x // "is"
>     println super.x // "get"; GROOVY-1736 converts to "super.getX()"; GROOVY-6097 notes MME if no getter exists
>   }
> }
> new D().test() // consistent with "new C().test()"
> new D().test2() // see notes above
> println new D().x // "is"
> // and for additional reference:
> class Cat {
>   static boolean isX(self) { true }
>   static boolean getX(self) { false }
> }
> use (Cat) {
>   println x // "get"
>   println 'str'.x // "get" -- see GROOVY-5245 for isser only
> }
> {code}
> "getter" is preferred for the declaring class, but this switches to "isser" preference for subclasses.  Not sure if traits or default interface methods conform to this.  *Using {{@CompileStatic}} the preference is for "getter" in all cases.*
> Lastly, when adding an explicit "getter" to a subclass ({{D}} in this example), the "isser" preference remains.  It would be nice to have some kind of compiler warning for overriding the "getter" but not the "isser" (or vice versa) for a [Bb]oolean property.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)