Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8346461

Seal Paint and Material

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • jfx24
    • javafx
    • None
    • source
    • minimal
    • No compatibility risk: Paint and Material can't be extended by user code due to existing language rules.
    • Java API
    • JDK

      Summary

      Paint and Material cannot be extended by user code and will be sealed.

      Problem

      None of these classes can be extended by user code, because both classes either have a package-private constructor, or package-private abstract methods. Sealing these classes allows us to use exhaustive pattern matching.

      Solution

      Both classes can be compatibly sealed, since existing language rules prevent classes outside of the javafx.scene.paint package to extend Paint or Material.

      Specification

      --- a/modules/javafx.graphics/src/main/java/javafx/scene/paint/Paint.java
      +++ b/modules/javafx.graphics/src/main/java/javafx/scene/paint/Paint.java
      @@ -45,7 +45,8 @@
        *
        * @since JavaFX 2.0
        */
      -public abstract class Paint implements Interpolatable<Paint> {
      +public abstract sealed class Paint implements Interpolatable<Paint>
      +                                   permits Color, LinearGradient, RadialGradient, ImagePattern {
      
           static {
               Toolkit.setPaintAccessor(new Toolkit.PaintAccessor() {
      --- a/modules/javafx.graphics/src/main/java/javafx/scene/paint/Material.java
      +++ b/modules/javafx.graphics/src/main/java/javafx/scene/paint/Material.java
      @@ -45,7 +45,7 @@
        *
        * @since JavaFX 8.0
        */
      -public abstract class Material {
      +public abstract sealed class Material permits PhongMaterial {
      
           static {
               // This is used by classes in different packages to get access to

            mstrauss Michael Strauß
            mstrauss Michael Strauß
            Kevin Rushforth
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: