java-9

How to execute java jshell command as inline from shell or windows commandLine

爷,独闯天下 提交于 2019-12-21 06:41:05
问题 Are there any way to execute java command on REPL ( jshell ) as inline command without launching it? E.g. Perl inline command $perl -e 'printf("%06d", 19)' 000019 I have to launch jshell to run any command: $jshell | Welcome to JShell -- Version 9 | For an introduction type: /help intro jshell> String.format("%06d", 19) $1 ==> "000019" I found similar question here, but it's not feasible solution to create a separate jsh file for individual command. Another solution on same post is: echo "1+2

Gradle: Building a modularized library that is compatible with Java 8

送分小仙女□ 提交于 2019-12-21 05:12:15
问题 So Java 9 is there, soon to be followed by Java 10. Time we should make our libraries ready for use in Java 9 projects. I did it in the following way: provide a module-info.java added the (experimental) jigsaw plugin in build.gradle Manually made changes according to the guide on the gradle site instead of using the jigsaw plugin. So far, both approaches work fine, and I can use the generated Jar in Java 9 projects. The problem is, the resulting Jar is not compatible with Java 8 although I

Java 9 Modules and JUnit 4

对着背影说爱祢 提交于 2019-12-21 04:56:18
问题 Eclipse oxygen; windows 7; JDK 9 final from 9, 21; JUnit 4.12 and an existing application. As starting point the application can be compiled, executed and all JUnit Tests shows green. Now we use eclipse to generate the file module-info.java. The outcome looks like: module ch.commcity.topsort { exports ch.commcity.topsort; requires junit; } But with the error: junit cannot be resolved to module. The question is: How to tell the file that junit does not define any module and it should be run in

java 9: JLink created invalid images - missing module executable script

会有一股神秘感。 提交于 2019-12-21 04:42:22
问题 I am creating a sample application with 3 modules user , dept and account . In my user module, I have a main class and compile my modules with the following command: javac -d target --module-source-path src $(find -name "*.java") After compiling, execute following command for run: java -p target -m com.user/com.user.info.Launcher The output after running java modules are successful. But when trying to create runtime image using jlink the image created successfully but module executable script

Java 9, Set.of() and Map.of() varargs overloads [duplicate]

戏子无情 提交于 2019-12-21 03:13:26
问题 This question already has answers here : What is the point of overloaded Convenience Factory Methods for Collections in Java 9 (6 answers) Closed 2 years ago . I'm studying the factory methods for Immutable collections. I see the Set.of() method has 10 varargs overloading (same for Map.of() ). I really can't understand why there are so many. In the end the function ImmutableCollections.SetN<>(elements) gets called anyway. In the documentation I found this: While this introduces some clutter

Java 9 overlapping non-exported packages

独自空忆成欢 提交于 2019-12-21 02:04:15
问题 Various resources (infoq, jigsaw-dev, osdir) indicate that having the same package in different java modules will lead to a LayerInstantiationException , even when the packages are internal to the module (non-exported). This seems to be the exact opposite of what the requirements say : The Java compiler, virtual machine, and run-time system must ensure that modules that contain packages of the same name do not interfere with each other. If two distinct modules contain packages of the same

How to make Multi-Release JAR Files with Gradle?

旧城冷巷雨未停 提交于 2019-12-20 17:42:04
问题 Java9 introduces with Multi-Release JARs. Let's say that I have multimodule Gradle project using java8: project-root settings.gradle build.gradle /module1 /src ... (common maven structure) /module2 /module3 This is a common multi-module project in Gradle. Let's say I need MR-Jar for module1 . I can't add module1-java9 targeting Java9 because the base is on 8 - so far, both my Gradle and IntelliJ IDEA complains. Gradle is compiled with the java8, but I need to enable java9 runtime just for the

cannot compile Java 9 module with --patch-module in IntelliJ IDEA 2017.2.1

扶醉桌前 提交于 2019-12-20 17:27:00
问题 I am trying to acquaint myself with Java 9 modules and how to define them in IntelliJ. Among other things, I want to solve a split package problem using the --patch-module compiler/JVM flag and I don't know how to make it work in IntelliJ. I am using IntelliJ IDEA 2017.2.1 Build #IC 172.3544.35 with Java HotSpot(TM) 64-Bit Server VM (build 9+180, mixed mode). This is my source file MyImmutableList.java : package com.google.common.collect; public class MyImmutableList extends

cannot compile Java 9 module with --patch-module in IntelliJ IDEA 2017.2.1

巧了我就是萌 提交于 2019-12-20 17:26:32
问题 I am trying to acquaint myself with Java 9 modules and how to define them in IntelliJ. Among other things, I want to solve a split package problem using the --patch-module compiler/JVM flag and I don't know how to make it work in IntelliJ. I am using IntelliJ IDEA 2017.2.1 Build #IC 172.3544.35 with Java HotSpot(TM) 64-Bit Server VM (build 9+180, mixed mode). This is my source file MyImmutableList.java : package com.google.common.collect; public class MyImmutableList extends

takeWhile() working differently with flatmap

∥☆過路亽.° 提交于 2019-12-20 08:29:30
问题 I am creating snippets with takeWhile to explore its possibilities. When used in conjunction with flatMap, the behaviour is not in line with the expectation. Please find the code snippet below. String[][] strArray = {{"Sample1", "Sample2"}, {"Sample3", "Sample4", "Sample5"}}; Arrays.stream(strArray) .flatMap(indStream -> Arrays.stream(indStream)) .takeWhile(ele -> !ele.equalsIgnoreCase("Sample4")) .forEach(ele -> System.out.println(ele)); Actual Output: Sample1 Sample2 Sample3 Sample5