Skip to main content
The 2024 Developer Survey results are live! See the results
added 8 characters in body
Source Link
arshajii
  • 128.9k
  • 26
  • 243
  • 291

Try something like this:

public boolean checkNull() throws IllegalAccessException {
    for (Field f : getClass().getFieldsgetDeclaredFields())
        if (f.get(this) != null)
            return false;
    return true;            
}

Although it would probably be better to check each variable if at all feasible.

Try something like this:

public boolean checkNull() throws IllegalAccessException {
    for (Field f : getClass().getFields())
        if (f.get(this) != null)
            return false;
    return true;            
}

Although it would probably be better to check each variable if at all feasible.

Try something like this:

public boolean checkNull() throws IllegalAccessException {
    for (Field f : getClass().getDeclaredFields())
        if (f.get(this) != null)
            return false;
    return true;            
}

Although it would probably be better to check each variable if at all feasible.

Source Link
arshajii
  • 128.9k
  • 26
  • 243
  • 291

Try something like this:

public boolean checkNull() throws IllegalAccessException {
    for (Field f : getClass().getFields())
        if (f.get(this) != null)
            return false;
    return true;            
}

Although it would probably be better to check each variable if at all feasible.