java-9

Using List.of for immutable list with single element instead of Collections.singletonList

佐手、 提交于 2019-12-30 10:28:10
问题 Java 9 introduce factory methods to create immutable lists with List.of . Which is more suitable to create an immutable list of one element ? List<String> immutableList1 = List.of("one"); List<String> immutableList2 = Collections.singletonList("one"); 回答1: Prefer using factory method List<String> immutableList1 = List.of("one"); Because they disallow null elements is one of the benefit and also factory methods in List interface are handy to add multiple objects and creates immutable List They

Why do we need requires static in java-9 module system? [duplicate]

China☆狼群 提交于 2019-12-30 10:06:32
问题 This question already has answers here : What's the difference between requires and requires static in module declaration (2 answers) Does the Java 9 Module system support optional dependencies? (1 answer) Closed 8 months ago . I started to learn jigsaw java-9 feature and read some articles/video. I can't understand concept of optional dependencies( requires static ) quote from article: When a module needs to be compiled against types from another module but does not want to depend on it at

log4j2 configuration file not found with java 9

佐手、 提交于 2019-12-30 10:05:34
问题 I had a Java 8 project and my configuration file was in resource folder and everything worked fine. Now I switched to Java 9, added requirement for log4j.api , and configuration file cannot be found anymore. Do I need to add something else in my module-info file for the logger to find it's config? For now, it's like this module project.main { requires jdk.incubator.httpclient; requires jackson.databind; requires jackson.core; requires jackson.annotations; requires log4j.api; } The Project

When will Eclipse support Java 9 natively?

拥有回忆 提交于 2019-12-30 08:41:47
问题 I know that there is a plug-in Java 9 Support for Oxygen but does anyone know when will Eclipse support Java 9 natively? I looked on project website and blog (planet eclipse) but can't find any information. 回答1: Support for JDK 9 and JUnit 5 will come with Eclipse Oxygen.1a, October 11, 2017. See also the announcement on the Eclipse [cross-project-issues-dev] mailing list. Update : The above mentioned version is released (see my video that shows the built-in Java 9 and JUnit 5 support of the

java.io.IOException: invalid constant type: 19 at 5

拈花ヽ惹草 提交于 2019-12-30 06:30:12
问题 I have a project. It uses spring boot 2 , java 9 and maven. It can be build sucessfully using mvn clean package . To run spring boot application I used the command java -jar java-cloud-rest-api/target/java-cloud-rest-api-0.0.1-SNAPSHOT.jar But it failed with error org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]:

What is an open module in Java 9 and how to use it

强颜欢笑 提交于 2019-12-30 03:43:11
问题 What is the difference between module with open keyword before and without it? For instance: open module foo { } module foo { } 回答1: In order to provide reflective access to your module, Java 9 introduced open keyword. You can create open module by using open keyword in module declaration. An open module grants reflective access to all of it's packages to other modules. For example, if you want to use some framework, that heavily relies on reflection, such as Spring, Hibernate etc, you can

Java 9 JavaFX Preloader

99封情书 提交于 2019-12-30 03:25:27
问题 In Java 8 I can launch a JavaFX application with a preloader using the following method: LauncherImpl.launchApplication(WindowMain.class, WindowMainPreloader.class, new String[]{...}); I prefer to start it from code, like above, instead of using a deploy configuration, because I don't want the graphical interface to start every time I start the application, but only after some code that has computed that the application should run in GUI mode. I was using the class "com.sun.javafx.application

Self-Contained Applications, built in Java

耗尽温柔 提交于 2019-12-30 01:16:05
问题 I've watched a few online presentations that briefly mentioned self-contained applications in Java 9, but I have a question that I would like cleared up. With the new module system, you're now allowed to only include the minimum amount of code required to run your application. However, does the system that wishes to run the application still require the JRE, or is that something that can be included in the base module within the program? I suspect it's the latter, as the page (here) to

String concatenation in a for loop. Java 9

末鹿安然 提交于 2019-12-29 06:48:09
问题 Please correct me if i'm wrong. In Java 8, for performance reasons, when concatenating several strings by the "+" operator StringBuffer was invoked. And the problem of creating a bunch of intermediate string objects and polluting the string pool was "resolved". What about Java 9? There'a new feature added as Invokedynamic. And a new class that resolves the problem even better, StringConcatFactory. String result = ""; List<String> list = Arrays.asList("a", "b", "c"); for (String n : list) {

Does Project Lombok support Java 9?

只谈情不闲聊 提交于 2019-12-29 04:08:38
问题 I have used Lombok in my project, but my colleague do not agree to use it, and his reason is (from controversy of lombok documents) Both of these pieces of Project Lombok make use of non-public APIs to accomplish their sorcery. This means that there is a risk that Project Lombok will be broken with subsequent IDE or JDK releases. But it's a very old document written in 2010, maybe now it has resolved the problem, so I want to know if Lombok will support Java 9 and does it still use the non