fork(5) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.lang.reflect.*;
  6. import java.io.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. Test t = new Test();
  14. t.testNull();
  15. }
  16. }
  17.  
  18. class Test {
  19. private String alpha;
  20. private String beta;
  21.  
  22. public void testNull() {
  23. Field[] fields = getClass().getDeclaredFields(); // get all the fields from your class.
  24. for (Field f : fields) { // iterate over each field...
  25. try {
  26. if (f.get(this) == null) { // evaluate field value.
  27. System.out.println(f.getName());
  28. }
  29. } catch (IllegalArgumentException ex) {
  30. ex.printStackTrace();
  31. } catch (IllegalAccessException ex) {
  32. ex.printStackTrace();
  33. }
  34. }
  35. }
  36. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
alpha
beta