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 2023/09/13 16:42:00 UTC
[jira] [Updated] (GROOVY-8859) traits allow access to private fields and static methods but not instance methods
[ https://issues.apache.org/jira/browse/GROOVY-8859?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-8859:
--------------------------------
Issue Type: Bug (was: Question)
> traits allow access to private fields and static methods but not instance methods
> ---------------------------------------------------------------------------------
>
> Key: GROOVY-8859
> URL: https://issues.apache.org/jira/browse/GROOVY-8859
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Reporter: Eric Milles
> Assignee: Eric Milles
> Priority: Minor
> Labels: trait, traits
>
> It seems that private in a trait is akin to protected in a class. For example a class that implements a trait may access private fields (through namespace syntax) and properties and call private static methods. And it may use Type.super.method() to disambiguate methods if necessary. *Why, however, can a class that implements a trait not call private instance methods?* This is not really covered in the language specification.
> {code:groovy}
> trait T {
> private void privit() {
> println 'private'
> }
> public void publik() {
> println 'public'
> }
> }
> class C implements T {
> def m() {
> publik()
> privit()
> }
> }
> new C().m()
> {code}
> This fails with missing method. But if static modifier is added to privit, it succeeds.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)