For Coin 8: this keyword for static methods

Vimil Saju vimilsaju at yahoo.com
Sat Feb 26 16:59:08 PST 2011


Yes that was my question, but for a static method isn't the current class and the class to which the static method belongs to the same?

--- On Sat, 2/26/11, Paul Benedict <pbenedict at apache.org> wrote:

From: Paul Benedict <pbenedict at apache.org>
Subject: Re: For Coin 8: this keyword for static methods
To: "Vimil Saju" <vimilsaju at yahoo.com>
Cc: coin-dev at openjdk.java.net, "Rémi Forax" <forax at univ-mlv.fr>
Date: Saturday, February 26, 2011, 4:54 PM

I thought the original question was to find a way to remove the static class name. That's not anything that needs computation at runtime. The compiler can emit it.

On Sat, Feb 26, 2011 at 6:47 PM, Vimil Saju <vimilsaju at yahoo.com> wrote:

Hi,



>From your blog I see that in JDK7 the code

  MethodHandles.lookup().lookupClass()

returns the current class. I read it is also possible to get the current class from the stack trace.



However from a performance point of view wouldn't having a keyword of some sort to get the current class be more efficient than having to go-through the stack trace to determine the current class, or does the JVM also have to do the same thing to determine the current class?




Thanks

Vimil



--- On Sat, 2/26/11, Rémi Forax <forax at univ-mlv.fr> wrote:



> From: Rémi Forax <forax at univ-mlv.fr>

> Subject: Re: For Coin 8: this keyword for static methods

> To: coin-dev at openjdk.java.net

> Date: Saturday, February 26, 2011, 1:35 PM

> On 02/22/2011 06:47 PM, Vimil Saju

> wrote:

> > Hi,

> >

> >   It would be nice to have a 'this'

> >   keyword for static methods. For

> static methods 'this' refers

> >   to the class in which the static

> method is defined.

> >

> >   In our code-base we have a lot of

> places where we

> >   initialize a logger for a class as

> follows

> >

> >   public class MyApp {

> >      static Logger logger =

> Logger.getLogger(MyApp.class);

> >      ...

> >      ...

> >

> > If we could refer to MyApp using the keyword 'this'

> then when copying this code to other classes there wouldn't

> be a need to remember to change the class passed to the

> getLogger method.

> >

> > Thanks

> > Vimil

>

> see my blog :)

> http://weblogs.java.net/blog/forax/archive/2010/10/26/how-get-current-class-java

>

> Rémi

>

>

>

>














      


More information about the coin-dev mailing list