Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7412

Map-to-interface cast: map method definition does not override the default method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.3
    • 2.5.3
    • groovy-runtime
    • None
    • JDK 1.8u45
      Ubuntu 15.04 x86_64
      Groovy 2.4.3
    • Important

    Description

      The following code

      import groovy.lang.GroovyShell;
      import org.codehaus.groovy.control.CompilerConfiguration;
      
      public class InterfaceDefaultMethods {
      
          public static void main(String... args) throws Exception {
              final CompilerConfiguration cc = new CompilerConfiguration();
              cc.setTargetBytecode(CompilerConfiguration.JDK8);
              final GroovyShell shell = new GroovyShell(cc);
              final X x = (X) shell.evaluate("[x : {-> 3}, z: {-> 19}] as " + X.class.getCanonicalName());
              System.out.format("x = %d, y = %d, z = %d%n", x.x(), x.y(), x.z());
          }
      
          public interface X {
      
              default int x() {
                  return 1;
              }
      
              default int y() {
                  return 2;
              }
      
              int z();
          }
      }
      

      produces

      x = 1, y = 2, z = 19
      

      but x must be 3.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              dmovchinn Dmitry Ovchinnikov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: