Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java this(null)

Tags:

java

this

I want to know what does this means?

public Settings() {
    this(null);
}

The above code is the constructor of a class "Settings". What does this(null) means here?

like image 267
Osman Khalid Avatar asked May 18 '12 18:05

Osman Khalid


1 Answers

public Settings() {
    this(null); //this is calling the next constructor
}
public Settings(Object o) {
//  this one
}

This is often used to pass default values so you can decide to use one constructor or another..

public Person() {
    this("Name"); 
}
public Person(String name) {
    this(name,20)
}
public Person(String name, int age) {
    //...
}
like image 190
porfiriopartida Avatar answered Oct 07 '22 00:10

porfiriopartida