Questions tagged [preview-feature]

21 questions
44
votes
3 answers

Compile and execute a JDK preview feature with Maven

With JDK/12 EarlyAccess Build 10, the JEP-325 Switch Expressions has been integrated as a preview feature in the JDK. A sample code for the expressions (as in the JEP as well): Scanner scanner = new Scanner(System.in); Day day =…
Naman
  • 27,789
  • 26
  • 218
  • 353
18
votes
4 answers

Java records with nullable components

I really like the addition of records in Java 14, at least as a preview feature, as it helps to reduce my need to use lombok for simple, immutable "data holders". But I'm having an issue with the implementation of nullable components. I'm trying to…
Leikingo
  • 890
  • 3
  • 10
  • 23
13
votes
4 answers

Error:java: error: invalid source release: 13 using JDK12 with IntelliJ

I am trying to build a project with JDK-12 ea. While trying to execute a sample class: public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int value = scanner.nextInt(); // After JEP-325 switch (value)…
Naman
  • 27,789
  • 26
  • 218
  • 353
11
votes
2 answers

how to set the use --enable-preview compile and run flags from gradle?

Looking to use records from Java 14 in a gradle build, but am getting: thufir@dur:~/NetBeansProjects/FileWatcherHandler$ thufir@dur:~/NetBeansProjects/FileWatcherHandler$ gradle clean build > Task :compileJava…
Thufir
  • 8,216
  • 28
  • 125
  • 273
10
votes
1 answer

Why does an incomplete switch expression compile successfully

Trying out JDK/12 EarlyAccess Build 20, where the JEP-325 Switch Expressions has been integrated as a preview feature. A sample code for the expressions (as in the JEP as well): Scanner scanner = new Scanner(System.in); Day day =…
Naman
  • 27,789
  • 26
  • 218
  • 353
9
votes
4 answers

Records in jlink:ed application throws exception

Using records (preview feature java-14) in a jlink:ed application, gives below error when using options: options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages'] java.lang.ClassFormatError: Invalid constant pool index…
Aksel Willgert
  • 11,367
  • 5
  • 53
  • 74
7
votes
2 answers

Pattern matching instanceof

I came across this amazing topic on https://www.baeldung.com/java-pattern-matching-instanceof. But when I try to run the following code, it throws compile time error: if(obj instanceof String s) { System.out.println(s); } The error…
user13120093
5
votes
1 answer

How do I enable "--enable-preview" for tests?

How do I enable "--enable-preview" for tests in Kotlin-based Gradle script ? I tried literally everything I could find online with https://stackoverflow.com/a/61849770/226895 being the closest to correct answer. I still get following error on :test…
expert
  • 29,290
  • 30
  • 110
  • 214
4
votes
1 answer

Is it possible to use Class with the new Pattern-Matching switch?

As part of an investigation into the parameters of a method, I tried the new Pattern Matching for switch (Preview). Using a traditional condition, it works perfectly: Method firstMethod = BitSet.class.getDeclaredMethods()[0]; Parameter…
yoni
  • 1,164
  • 2
  • 13
  • 29
4
votes
1 answer

Skip Spot Bugs stack traces when features require ASM8_EXPERIMENTAL

I'm using spotbugs-maven-plugin 4.0.0 (+ spotbugs 4.0.2 dependency). The problem is that it cannot recognize Java 14 records. Every time when it finds a record or a class that uses that record, it prints a long stacktrace. [INFO] >>>…
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
4
votes
1 answer

Maven Exec Plugin with Preview Features

It's easy to compile your Java sources with --enable-preview: org.apache.maven.plugins maven-compiler-plugin 3.8.1
2
votes
1 answer

.NET 6 Preview 7: Runtime errors with generic math

I'm not sure if I've discovered a bug or if I'm doing something wrong, but this issue is not listed in the known issues of .NET 6: I've got a unit test project with a single file that looks like this: using System; using…
Nigel
  • 2,961
  • 1
  • 14
  • 32
2
votes
0 answers

Using cannonical constructor of local record (preview-feature) in Eclipse causes verify error

I am Trying to use records preview-feature with cannonical constructors in Eclipse . public class Example { public static void main(String[] args) { record Range() { Range { } } new Range(); …
Gonen I
  • 5,576
  • 1
  • 29
  • 60
1
vote
1 answer

How to run a single Java file with preview features enabled in Netbeans 12?

I have created a Java Maven project with Java version 14 in Netbeans. I have already instructed the compiler to enable preview features, and that works. Now I have a bunch of classes containing main methods, and I want to execute one of them using…
MC Emperor
  • 22,334
  • 15
  • 80
  • 130
0
votes
1 answer

What are unconditional patterns? (Java 19) [preview] unconditional patterns in instanceof are a preview feature and may be removed in a future release

I am working in Java 19, and using the pattern matching for instanceof that was released in JEP 394 (which released in Java 16). However, I am running into a warning that I am struggling to understand. public class…
davidalayachew
  • 1,279
  • 1
  • 11
  • 22
1
2