title: Java, Object-independent null return
body: <p>Given Java source code and a preprocessor (like C++), I would like to replace all mentions of null with a function that returns null. It finds a call to null and replaces it with the following function.</p>
  
  <pre><code>public static Object returnNull(){
      return null;
  }
  </code></pre>
  
  <p>This fails because there are varied classes and:</p>
  
  <pre><code>functionThatWantsCustomClass( returnNull() ); //Object cannot be converted to CustomClass
  </code></pre>
  
  <p>or</p>
  
  <pre><code>if( cc == returnNull() ) //Object cannot be converted to CustomClass
  </code></pre>
  
  <p>etc.</p>
  
  <p>Easiest solution I can imagine is having to parametrize the preprocessor, although that would require going through every single null to add the parameter maually, eg: <code>null/*CustomClass*/</code>.</p>
  
  <p>Another method is spending a lot of time writing a much better parser so it always knows the required class for a returnTypedNull() function.</p>
  
  <p>Is there a way to get through this error with minimal modification/parsing? </p>