title: When two interfaces have conflicting return types, why does one method become default?
body: <p>In Java 8, if I have two interfaces with different (but compatible) return types, reflection tells me that one of the two methods is a <strong>default</strong> method, even though I haven't actually declared the method as default or provided a method body.</p>
  
  <p>For instance, take the following code snippet:</p>
  
  <pre><code>package com.company;
  import java.lang.reflect.Method;
  
  interface BarInterface {}
  class Bar implements BarInterface {}
  
  interface FooInterface {
      public BarInterface getBar();
  }
  
  interface FooInterface2 extends FooInterface {
      public Bar getBar();
  }
  
  class Foo implements FooInterface2 {
      public Bar getBar(){
          throw new UnsupportedOperationException();
      }
  }
  
  public class Main {
      public static void main(String[] args) {
          for(Method m : FooInterface2.class.getMethods()){
              System.out.println(m);
          }
      }
  }
  </code></pre>
  
  <p>Java 1.8 produces the following output:</p>
  
  <pre><code>public abstract com.company.Bar com.company.FooInterface2.getBar()
  public default com.company.BarInterface com.company.FooInterface2.getBar()
  </code></pre>
  
  <p>This seems odd, not only because both methods are present, but also because one of the methods has suddenly and inexplicably become a <strong>default</strong> method.</p>
  
  <p>Running the same code in Java 7 yields something a little less unexpected, albeit still confusing, given that both methods have the same signature:</p>
  
  <pre><code>public abstract com.company.Bar com.company.FooInterface2.getBar()
  public abstract com.company.BarInterface com.company.FooInterface.getBar()
  </code></pre>
  
  <p>Java definitely doesn't support multiple return types, so this result is still pretty strange.  </p>
  
  <hr>
  
  <p>The obvious next thought is: "Okay, so maybe this is a special behavior that only applies to interfaces, because these methods have no implementation."  </p>
  
  <p>Wrong.  </p>
  
  <pre><code>class Foo2 implements FooInterface2 {
      public Bar getBar(){
          throw new UnsupportedOperationException();
      }
  }
  
  public class Main {
      public static void main(String[] args) {
          for(Method m : Foo2.class.getMethods()){
              System.out.println(m);
          }
      }
  }
  </code></pre>
  
  <p>yields</p>
  
  <pre><code>public com.company.Bar com.company.Foo2.getBar()
  public com.company.BarInterface com.company.Foo2.getBar()
  </code></pre>
  
  <p>What's going on here?  Why is Java enumerating these as separate methods, and how has one of the interface methods managed to become a default method with no implementation?</p>