title: Creating a "logical exclusive or" operator in Java
body: <h2>Observations:</h2>
  
  <p>Java has a logical AND operator.<BR>
  Java has a logical OR operator.<BR>
  Java has a logical NOT operator.<BR>
  <BR></p>
  
  <h2>Problem:</h2>
  
  <p>Java has no logical XOR operator, <a href="http://java.sun.com/docs/books/tutorial/java/nutsandbolts/operators.html" rel="noreferrer">according to sun</a>.  I would like to define one.<BR>
  <BR></p>
  
  <h2>Method Definition:</h2>
  
  <p>As a method it is simply defined as follows:</p>
  
  <pre><code>public static boolean logicalXOR(boolean x, boolean y) {
      return ( ( x || y ) &amp;&amp; ! ( x &amp;&amp; y ) );
  }
  </code></pre>
  
  <p><BR></p>
  
  <h2>Method Call:</h2>
  
  <p>This method is called in the following way:</p>
  
  <pre><code>boolean myVal = logicalXOR(x, y);
  </code></pre>
  
  <p><BR></p>
  
  <h2>Operator Usage:</h2>
  
  <p>I would much rather have an operator, used as follows:</p>
  
  <pre><code>boolean myVal = x ^^ y;
  </code></pre>
  
  <p><BR></p>
  
  <h2>Question:</h2>
  
  <p>I can't find anything on how to go about defining a new operator in Java.  Where should I start?</p>