title: Is there a way in Java to find the name of the variable that was passed to a function?
body: <p>I have a Java function called testForNull</p>
  
  <pre><code>   public static void testForNull(Object obj)
      {
       if (obj == null)
        {
          System.out.println("Object is null");
        }
      }
  </code></pre>
  
  <p>I use it to test multiple objects to ensure they are not null. But, I am unable to tell the name of the variable that way. </p>
  
  <p>For eg. if I say</p>
  
  <pre><code>    testForNull(x);
      testForNull(y);
      testForNull(z);
  </code></pre>
  
  <p>I cannot tell which of the three lines caused the "Object is null" output. Of course, I can simply add another parameter to the function and have something like</p>
  
  <pre><code>    testForNull(x, "x");
      testForNull(y, "y");
      testForNull(z, "z");
  </code></pre>
  
  <p>But I want to know whether it is possible to deduce the name of the variable without passing it explicitly. Thanks. </p>