title: How to make a method parameter dependent on other parameter
body: <p>How can I make a method parameter mandatory or optional based on another parameter in Java?</p>
  <p>For example, I have a Java method <code>public void example(int x, int y);</code>. Now I want that if <code>x</code> is provided as <code>0</code>, then method should be called without providing <code>y</code>, i.e. <code>example(0);</code> should work. However, if x is not <code>0</code> then method should also require <code>y</code>, i.e. <code>example(1);</code> should not work in this case.</p>