You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Cédric Champeau (JIRA)" <ji...@apache.org> on 2015/11/16 11:32:10 UTC

[jira] [Commented] (GROOVY-7674) Groovy ignore public field if class implement/extend Map

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

Cédric Champeau commented on GROOVY-7674:
-----------------------------------------

This is not a bug, but by design. See http://docs.groovy-lang.org/latest/html/documentation/#_map_property_notation

If you want to access a field, you must use the {{b.@name}} (attribute operator).

> Groovy ignore public field if class implement/extend Map
> --------------------------------------------------------
>
>                 Key: GROOVY-7674
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7674
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.5
>         Environment: linux, fedora
>            Reporter: Pavel Leonov
>
> Here is a simple example that demonstrates the issue:
> {code}
> package java_code;
> public class A {
>   public final String name;
>   public A( String name) {
>     this.name = name;
>   }
> }
> public class B extends LinkedHashMap<String, Object>{
>   public final String name;
>     public B( String name) {
>       this.name = name;
>     }
> }
> {code}
> {code}
> package groovy_code;
> A a = new A( 'object a' )
> B b = new B( 'object b' )
> println a.name // print object a
> println b.name // print null
> {code}
> Versions:
> Java 1.8.0_65
> Groovy 2.4.5



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)