Search code examples
javaspringspring-bootspring-mvcjavabeans

Super in Bean Class


I am using eclipse to create a java application in which i created a Survey class.

public class Survey {
private String id;
private String title;
private String description;


public Survey(String id, String title, String description) {
    super();
    this.id = id;
    this.title = title;
    this.description = description;
}

I used the auto generate in eclipse to create a constructor. It creates one with super() in it, I am not sure why? Since this class doesn't inherit any other class, what it's use?


Solution

  • This is done for the simplicity of the generator of the constructor method in Eclipse, there is no real reason to put it there in your code. How does this work? The code generator analyzes the superclass and generates a call to super that will include the parameters of the selected constructor. In this case the superclass is Object and selected constructor is the default one, hence no parameters. To omit this line would be a special case and developers of the code generator apparently decided not to implement it separately.