groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jochen Theodorou <>
Subject Re: Inner traits?
Date Mon, 29 Feb 2016 11:05:39 GMT

On 29.02.2016 11:52, Jesper Steen Møller wrote:
> Hi Jochen and Henry
>> On 29. feb. 2016, at 11.29, Jochen Theodorou <> wrote:
>> On 27.02.2016 19:29, Christophe Henry wrote:
>> [...]
>>> public class CustomApplication extends Application
>>> {
>>>      private static instance
> […]
>>>          public ContextgetApplicationContext(){return instance.applicationContext
>> Hmmm, I wonder if this can be made sense of or not. A trait can be seen as some independent
piece that can be added to a class. But for it to be independent, it cannot be non-static.
In your code the trait implementation would depend on an instance of CustomApplication and
cannot be created without supplying such an instance.
> Henry’s example refers to a static field, so it wouldn’t require the outer instance,
analogous to an interface (which is static by definition).

oh... I did not see that, thanks for the clarification.

> Those semantics should be easy enough to cope with, if only the grammar (and taste!)
would allow it.

Why does the grammar not allow it? The grammar does imho, but the later 
parts of the compiler are not prepared for that kind of trouble and 
either fail with BUG! messages (I had an NPE in one case for example) or 
produces code, which does not work.

All that mostly because traits have not been considered for use inside a 
class... Adding an appropriate error message for this would have been 
good. Or we go and fix it - which is not done so easily

bye Jochen

View raw message