Groovy中的“私人”意味着什么? [英] What does 'private' mean in Groovy?

查看:110
本文介绍了Groovy中的“私人”意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码设置了一个私有方法。所以私人真的是私人的吗?

  public class Person {
private String name
}

def u = new Person(name:Ron)
println u.name


解决方案

通过设计Groovy应该尊重私有修饰符,但是当前的实现不考虑它。
您可以在以下Jira条目中找到更多详情: org / browse / GROOVY-1591rel =nofollow noreferrer> Groovy JIRA 1591

  • Groovy JIRA 3010
    =https://stackoverflow.com/questions/2834700/groovy-call-private-method-in-java-super-class> groovy在Java超类中调用私有方法


    The following code sets a private method. So how private really is private?

    public class Person {
     private String name
    }
    
    def u = new Person(name:"Ron")
    println u.name
    

    解决方案

    By design Groovy should respect the private modifier, however the current implementation takes no account of it. You can find further details in the following Jira entries:

    There are also further details in groovy call private method in Java super class

    这篇关于Groovy中的“私人”意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆