java-12

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

怎甘沉沦 提交于 2019-12-05 12:17:26
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) { case 1 ->System.out.println("one"); case 2 ->System.out.println("two"); default ->System.out.println("many"); } } The IDE throws the error that reads Error:java: error: invalid source release: 13 Relevant project configuration screens : Module settings SDKs Compiler settings About IDE: IntelliJ IDEA 2018.3.3 (Community Edition) Build #IC-183.5153.38, built on

Problem running tests with enabled preview features in surefire and failsafe

时光毁灭记忆、已成空白 提交于 2019-12-05 02:21:17
I'm trying to migrate a project to Java 12, with --enable-preview . I added --enable-preview in compiler settings: <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <release>12</release> <compilerArgs> <arg>--enable-preview</arg> </compilerArgs> </configuration> </plugin> And also added it in argLine for surefire and failsafe: <properties> <argLine>--enable-preview</argLine> </properties> And do a mvn clean verify results in: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test (default-test) on project

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

谁说我不能喝 提交于 2019-12-03 12:11:30
问题 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 { try { Lookup lookupArrayList = MethodHandles.privateLookupIn(ArrayList.class, MethodHandles.lookup()); VAR_HANDLE_ARRAY_LIST = lookupArrayList.findVarHandle(ArrayList.class, "elementData", Object[].class); } catch (Exception e) { e.printStackTrace(); throw new

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

≡放荡痞女 提交于 2019-12-03 02:46:47
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 { try { Lookup lookupArrayList = MethodHandles.privateLookupIn(ArrayList.class, MethodHandles.lookup()); VAR_HANDLE_ARRAY_LIST = lookupArrayList.findVarHandle(ArrayList.class, "elementData", Object[].class); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(); } } public static void main(String[] args) { List<String> defaultConstructorList =

Compile a JDK12 preview feature with Maven

前提是你 提交于 2019-11-27 08:51:46
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 = Day.valueOf(scanner.next()); switch (day) { case MONDAY, TUESDAY -> System.out.println("Back to work.") ; case WEDNESDAY -> System.out.println("Wait for the end of week...") ; case THURSDAY,FRIDAY -> System.out.println("Plan for the weekend?"); case SATURDAY, SUNDAY -> System.out.println("Enjoy the holiday!"); } where Day being an enum as public enum Day { MONDAY,

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

心不动则不痛 提交于 2019-11-26 16:54:54
问题 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 java.base/java.lang.reflect=ALL-UNNAMED set. Any ideas how to achieve this? (Appart from the fact that this might be a bad idea, i want to be able to change a "static final" field in my code during junit testing via reflection. This has been possible with java8 by