The registrar does nothing special. This is just Java code.
public class SomeClass { private Logger logger = LogFactory.getLogger(SomeClass.class); public void doSomething() { this.logger.debug("foo"); } }
this.logger simply points to an instance variable called logger current instance ( this ). Prefix this. Incidentally, is supernatural in this example. You can also just do logger.debug("foo") here.
If it is not declared in SomeClass itself, it most likely was declared in an expanding class. Check out the class declared in extends .
As for your doubt about objectName.something1.something2 , have you already seen how System.out.println() works? System.out returns a PrintStream object, which in turn has println() . That way, if objectName.something returns a fully functional Object method using methods, you can simply continue calling chain methods.
Basically,
objectName.something1.something2;
can translate as
SomeObject someObject = objectName.something1; someObject.something2;
But if you do not need someObject anywhere else in the code, then you can simply shorten it, as in your example.
Update : according to your update:
So, logger is an object of the Logger class (but I don’t understand why they could not instantiate the class in the usual way using the “new Logger ()). I also don’t understand what exactly logger.severe (" ") is.
Just read the javadoc of this class that all this does . As to why this is not possible to create, this is because of the factory pattern.
Update 2 : according to another confusion:
I do not understand why they use "this". I mean, if I use only the field name, will it not be the default field of this object? Am I there any difference between "this.x" and "x"?
In this way, you can more clearly indicate which one you want to access. If the method contains, for example, an argument or a local variable called logger , then this.logger will still refer to the instance variable.
public class SomeClass { private Logger logger = LogFactory.getLogger(SomeClass.class); public void doSomething(Logger logger) { this.logger.debug("foo");