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

Groovy should support sealed classes

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 4.0.0-beta-1
    • Compiler
    • None

    Description

      For Java 15/16 under preview and targeted for 17+, sealed classes and interfaces can be created. It would be good for Groovy to support a similar capability.

      In addition, Groovy should behave properly in the presence of such Java-created classes, e.g. currently the compiler allows Groovy classes to extend sealed Java classes or implement sealed interfaces, but such classes when loaded will give a runtime error:

      java.lang.RuntimeException: java.lang.IncompatibleClassChangeError:
      class MyGroovyChildClass cannot inherit from sealed class MyJavaSealedClass
      

      Possible features:

      • Java allows the permitted list to be inferred where the classes are from the same source file.
      • Java allows sealed/non-sealed parts to the hierarchy.
      • We could use an annotation to carry sealed information for JDK8-16 versions.

      Advanced options should also be explored:

      • When creating sealed classes, Java currently requires all mentioned permitted children to be compiled in the source set. However, it does allow subsequent compilation steps to include just one of the children (and have the parent pre-compiled) though this can lead to IncompatibleClassChangeError problems. If these problems can be overcome, it might be possible to have mixed Java/Groovy hierarchies by using stubs initially. This should be explored further to understand if it is indeed possible.

      We should create a GEP which outlines what we want to do with respect to Groovy support for sealed hierarchies and discuss further there how we might implement the feature.

      GEP: https://groovy.apache.org/wiki/GEP-13.html

      Attachments

        Activity

          People

            paulk Paul King
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 40m
                40m