What does This.getclass () get?
This represents a reference to the current object;
GetClass () is a method in Java.lang.Object that returns the run-time class of an object;
This.getclass () is the run-time class that returns the current object.
What does Logger.getlogger (This.getclass ()) get?
He gets a logger object, and this logger will monitor the This.getclass () This runtime class, within which you may create log.info (""), Log.debug (""), ... Statements, these statements will output your logs based on your pre-defined logger level. As you write System.out.print (""), the difference is that logger can be controlled according to the level of log output as needed. (This is, of course, just one aspect)
Logger.getlogger (This.getclass ()) What are the benefits of writing this?
So you just have to write a line of code in the base class, and the subclass can be used directly, which is the principle of reuse.
- Package com.zhaipuhong.j2se.keywords;
- Public class Thiskeywordsa {
- protected String className = this.getclass (). toString ();
- Public Thiskeywordsa () {
- System.out.println ("thiskeywordsa className = =" + ClassName);
- }
- }
- Package com.zhaipuhong.j2se.keywords;
- Public class THISKEYWORDSB extends thiskeywordsa{
- Public THISKEYWORDSB () {
- System.out.println ("THISKEYWORDSB className = =" + ClassName);
- }
- /**
- * @param args
- */
- public static void Main (string[] args) {
- //TODO auto-generated method stub
- THISKEYWORDSB B = new THISKEYWORDSB ();
- }
- }
Operation Result:
THISKEYWORDSA ClassName = = Class Com.zhaipuhong.j2se.keywords.ThisKeywordsB
THISKEYWORDSB ClassName = = Class Com.zhaipuhong.j2se.keywords.ThisKeywordsB
Because B inherits A,a objects are first created (do not consider abstract classes and interface ^_^) and then create B objects as the word objects of the B object. The logger at this point is part of the B object and can be used by the B object.
This refers to the object of the child class
Private Logger Log=logger.getlogger (This.getclass ()) in Java;