title: In Java, when is the {a,b,c,...} array shorthand inappropriate, and why?
body: <p>If you're defining a variable, it appears to be perfectly valid to declare/define a variable as follows:</p>
  
  <pre><code>    double[][] output = {{0,0},{1,0}};
  </code></pre>
  
  <p>But if you're returning a value, it appears to be invalid to write the following:</p>
  
  <pre><code>    public double[] foo(){
        return {0,1,2}
      }
  </code></pre>
  
  <p>I would have thought that internally, both of these would have been performing the same action. Eclipse, at least, disagrees. Does anyone know what the difference is, and where else it can be seen, or why it would be beneficial to accept the former example and reject the latter?</p>
  
  <p>Edit: okay, so it's appropriate when you're initializing, but I don't see any ambiguity... couldn't the JVM interpret the type of variable from the name of the variable (in the case of redefining already initialized variables) or when returning (where the JVM could just look at the return type of the function)? What makes initialization a special case of a rule that would prohibit implicit type? What makes the general rule require explicit type?</p>