Static this !

ALAA MURAD alaamurad at gmail.com
Mon Mar 8 00:04:05 PST 2010


Hi everyone ,

This is my first proposal to Java open JDK , so I'm not sure I'm in the
right place.

I propose that Java will include a static equivalent to '"this" keyword.
like this "this#" to return the class is static scope.

I had this needs because of the logger as every time you want to use the
static class inside the class itself you need to hard code that.

Example :

private static Logger logger = Logger.getLogger("com.Customer");  <--
hardcoded class name !
// or private static Logger logger =
Logger.getLogger(Customer.class.getName());  <-- Still hardcoded class

public static void getCustomerName(){
...
logger.log(...);
}

As you can see, that I had to hardcoded the "com.Customer", if my logger was
non-static , it would have been easy and I would just did the following:


private static Logger logger = Logger.getLogger(this.getClass().getName());

But I'm proposing ?

private static Logger logger = Logger.getLogger(this#.class.getName()); <--
this way you can copy & paste that at any class, right ?



As you can see "this#" will return my class in a static scope.

I came to this problem because I had to copy & paste (private static Logger
logger = Logger.getLogger("Some Class Name ...");) and rewrite the class
name !!! into hundreds of classes.

Best Regards,
Alaa Murad





-- 
Alaa Murad
E-Service Development Department
Bank ALJazira
Website: http://www.alaamurad.com
Email: alaa at alaamurad.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-grammar-dev/attachments/20100308/d4e8c37c/attachment.html 


More information about the compiler-grammar-dev mailing list