Skip to content

Latest commit

 

History

History

java-preview-features

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

java-preview-features

Configure Gradle to build and run a project that uses Java Preview Features.

Overview

This repo in particular showcases the Unnamed Patterns and Variables preview language feature in Java 21. Preview features are hidden behind the --enable-preview Java flag.

Please note: Intellij won't always support preview features!

Instructions

Follow these instructions to build and run the demo program.

  1. Pre-requisite: Java 21
  2. Build and run the program:
    • ./gradlew run
    • It should output the following.

      > Task :compileJava
      Note: /Users/dave/repos/personal/gradle-playground/java-preview-features/src/main/java/dgroomes/java_preview_features/App.java uses preview features of Java SE 21.
      Note: Recompile with -Xlint:preview for details.
      
      
      > Task :run
      Found 631 time zones
      

      Notice the warning:

      Note: /...omitted.../App.java uses preview features of Java SE 21.

      There is no way to suppress this because Java's preview features are designed to allow breaking changes in future releases, so the compile-time reminder is a welcome one.

  3. Run the tests:
    • ./gradlew test

Wish List

General clean-ups, TODOs and things I wish to implement for this project:

  • DONE (I could still use the planet types very effectively thanks to "pattern matching for switch") Upgrade to Java 20 and use a Java 20 preview feature. This will require throwing away the planet design for something else.