title: Case over type (switch with return value)
body: <p>The question <a href="https://stackoverflow.com/q/29570767/905686">Switch over type in java</a> considers how one can switch on code to be executed depending on an object's type.</p>
  
  <p>Now I want to have a <code>case</code> statement in the way it is used in many functional languages:</p>
  
  <pre><code>r = case x of
     String s -&gt; s
     Int i -&gt; toString i
  </code></pre>
  
  <p>That is, I want to switch on the type and also regard the switch statement as an expression (i.e., it should have a result).</p>
  
  <p>Like in a switch, it should be allowed that multiple cases match but the evaluation will check from first to last and return the value of the first match (and null if there is no match).</p>
  
  <p>It could be in the style of <a href="https://stackoverflow.com/a/37334159/905686">this answer</a> to the aforementioned question which uses Java 8 functional features:</p>
  
  <pre><code>switchType(x,
      caze(String.class, v -&gt; print("String: " + v),
      caze(Integer.class, v -&gt; print("Int: " + v));
  </code></pre>