Skip to main content
The 2024 Developer Survey results are live! See the results
added 2 characters in body
Source Link
th3an0maly
  • 3.5k
  • 8
  • 35
  • 54

This would mean that the class was initialized, but the variables were not set.

A sample Class:

public class User {

    String id = null;
    String name = null;

    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

The actual class is huge that I prefer not to check if(xyz == null)if(xyz == null) for each of the variables.

This would mean that the class was initialized, but the variables were not set.

A sample Class:

public class User {

    String id = null;
    String name = null;

    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

The actual class is huge that I prefer not to check if(xyz == null) for each of the variables.

This would mean that the class was initialized, but the variables were not set.

A sample Class:

public class User {

    String id = null;
    String name = null;

    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

The actual class is huge that I prefer not to check if(xyz == null) for each of the variables.

Source Link
th3an0maly
  • 3.5k
  • 8
  • 35
  • 54

What is the best way to know if all the variables in a Class are null?

This would mean that the class was initialized, but the variables were not set.

A sample Class:

public class User {

    String id = null;
    String name = null;

    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

The actual class is huge that I prefer not to check if(xyz == null) for each of the variables.