Questions tagged [java-12]

Use this tag for questions specific to Java 12, which is version 12 of the Java platform, released on 19 March 2019. In most cases you should also specify the java tag.

This release is the Reference Implementation of version 12 of the Java SE Platform, as specified by JSR 386 in the Java Community Process.

The JDK/12 production-ready binaries are available for Linux and Windows.

Initial JEPs targetted with this are

Java 12 Final Release Specification

113 questions
56
votes
1 answer

Mystifying microbenchmark result for stream API on Java 12 vs. Java 8 with -gc true

As part of my investigation on the difference between using a complex filter or multiple filters in streams, I notice that performance on Java 12 is way slower than on Java 8. Is any explanation for those weird results? Did I miss something here?…
Serge
  • 2,094
  • 15
  • 26
46
votes
1 answer

Why does Java 12 try to convert the result of a switch to a number?

I agree that this code: var y = switch (0) { case 0 -> '0'; case 1 -> 0.0F; case 2 -> 2L; case 3 -> true; default -> 4; }; System.out.println(y); System.out.println(((Object) y).getClass().getName()); returns…
Ilya
  • 702
  • 6
  • 13
36
votes
2 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
  • 23,555
  • 22
  • 173
  • 290
29
votes
9 answers

The package org.w3c.dom is accessible from more than one module: , java.xml

I am unable to import org.w3c.dom.NodeList package to Eclipse. It is showing The package org.w3c.dom is accessible from more than one module: , java.xml" error message in eclipse. Please let me know how to fix this ? Eclipse…
poovaraj
  • 429
  • 1
  • 5
  • 10
24
votes
2 answers

Get declared fields of java.lang.reflect.Fields in jdk12

In java8 it was possible to access fields of class java.lang.reflect.Fields using e.g. Field.class.getDeclaredFields(); In java12 (starting with java9 ?) this returns only a empty array. This doesn't change even with --add-opens…
Henning
  • 981
  • 1
  • 8
  • 18
21
votes
3 answers

How to enable Java 12 preview features with Gradle?

When I tried to build my Java code which has switch expressions using Gradle, it throws this error: error: switch expressions are a preview feature and are disabled by default. I tried running ./gradlew build --enable-preview which didn't work…
Murali Krishna
  • 499
  • 1
  • 7
  • 15
20
votes
3 answers

Problem running tests with enabled preview features in surefire and failsafe

I'm trying to migrate a project to Java 12, with --enable-preview. I added --enable-preview in compiler settings: maven-compiler-plugin
16
votes
2 answers

Java 11/12 Javadoc with maven results in not generating Javadocs for tests

I have a small project with the following structure: pom.xml src/main/java/ module-info.java de.ps.pl.te/ package-info.java TE.java src/test/java/ de.ps.pl.te.test/ package-info.java TETests.java Also within my maven pom…
PowerStat
  • 3,252
  • 7
  • 25
  • 47
14
votes
6 answers

Why does using different ArrayList constructors cause a different growth rate of the internal array?

I seem to stumble across something interesting in ArrayList implementation that I can't wrap my head around. Here is some code that shows what I mean: public class Sandbox { private static final VarHandle VAR_HANDLE_ARRAY_LIST; static { …
Eugene
  • 102,901
  • 10
  • 149
  • 252
12
votes
2 answers

How to use JDK 12 with Android project

I am running Android Studio 3.5 Beta 5. I have been following a rabbit hole starting with trying to run unit tests with Robolectric against Android SDK 29. I saw an error that required running with Java 9. When I went to install JDK 9, it directed…
B W
  • 582
  • 1
  • 6
  • 19
12
votes
3 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
  • 23,555
  • 22
  • 173
  • 290
10
votes
2 answers

VarHandle get/setOpaque

I keep fighting to understand what VarHandle::setOpaque and VarHandle::getOpaque are really doing. It has not been easy so far - there are some things I think I get (but will not present them in the question itself, not to muddy the waters), but…
Eugene
  • 102,901
  • 10
  • 149
  • 252
10
votes
1 answer

-XX:+StressLCM, -XX:+StressGCM Options for JVM

While playing with some jcstress code, I noticed two parameters that are very new to me: StressLCM and StressGCM. The very first thing to do for me was searching for these in the source code itself and while I have found some things, it is still…
Eugene
  • 102,901
  • 10
  • 149
  • 252
10
votes
1 answer

How to use Java 12's Microbenchmark Suite?

According to JEP 230: Microbenchmark Suite, there exists a microbenchmark suite built-in to Java 12. The JEP explains that it's basically JMH, but without needing to explicitly depend on it using Maven/Gradle. However, it doesn't specify how to go…
Jacob G.
  • 26,421
  • 5
  • 47
  • 96
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
  • 23,555
  • 22
  • 173
  • 290
1
2 3 4 5 6 7 8