title: Ternary operator in Java 8, compilation with Maven
body: <p>Consider this class:</p>
  
  <pre><code>package be.duo.test;
  
  public class Main {
  
      public static void main(String[] args) {
          Main main = new Main();
          main.execute();
      }
  
      private void execute() {
          for(int i = 0; i &lt; 10; i++) {
              System.out.println("" + method());
          }
      }
  
      private int method() {
          return (Math.random() &gt; 0.5d) ? 1 : null;
      }
  
  }
  </code></pre>
  
  <p>The method() has return type <code>int</code>, which is a primitive type.</p>
  
  <p>Consider the ternary operator used in the return statement:</p>
  
  <ul><li>it compiles with the Java 8 default compiler, but this will result in a NullPointerException at runtime, why?</li>
  <li>using Maven this will result in a compile time error</li>
  </ul>
  
  <pre><code>[ERROR] error: incompatible types: bad type in conditional expression
  [ERROR] &lt;null&gt; cannot be converted to int
  </code></pre>
  
  <p>Can somebody explain to me <strong>why</strong> it behaves different?</p>