For Coin 8: this keyword for static methods

Vimil Saju vimilsaju at yahoo.com
Sat Feb 26 16:47:52 PST 2011


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