groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Дионисьев Павел <>
Subject Re: `this` in static context
Date Mon, 06 Nov 2017 17:54:00 GMT
No, I’m not talking about closures. Normal static methods and static initialisers.
Honestly, I remember using it years ago. Not recently though.

It’s a small but handy thing to have when you are defining stuff like loggers manually.

Imagine code like this: // AFAIK it should work now.

class LongClassName { 
  private static Logger log = Logger.getLogger( // instead of duplicating class
name here. Logger.getLogger(LongClassName.class.getName())

It simplifies manual class renaming, and eliminates chances of error.

I was sure it should work, but seems not in IDEA. So, I’m guessing, is it IDEA bug, or intended


> On 6 Nov 2017, at 18:45, <> <>
> For sure , "this" and "super" are supported within a closure defined in a static context.
 Are you saying they also work directly in a static method?  Given "class A { static main(args}
{ this } }", this should be of type "Class<A>" if it is indeed supported.  It follows
that it would work, since you can call directly methods on Class<A> from that scope,
like getCanonicalName().

View raw message