java-9

Why does compilation of public APIs leaking internal types not fail?

点点圈 提交于 2019-12-22 03:35:18
问题 I have the follwing Java 9 module: module com.example.a { exports com.example.a; } With an exported type: public class Api { public static void foo(ImplDetail args) {} } And a non-exported type: package com.example.b.internal; public class ImplDetail {} The exported type uses the non-exported type as a method parameter type in a public method. I'd have assumed that the compiler would reject such an inconsistent class configuration, as clients in other modules could not really invoke the foo()

Meaning of lambda () -> { } in Java

风格不统一 提交于 2019-12-22 01:13:23
问题 I am looking at the following Stack Overflow answer: How to change Spring's @Scheduled fixedDelay at runtime And in the code there is the following line: schedulerFuture = taskScheduler.schedule(() -> { }, this); I would like to know what the lambda () -> {} means in that code. I need to write it without using lambdas. 回答1: Its a Runnable with an empty run definition. The anonymous class representation of this would be: new Runnable() { @Override public void run() { // could have done

How to run Java 9 application with classpath rather than module path in IDEA?

我的梦境 提交于 2019-12-21 23:09:29
问题 When I run a main class in IDEA, it puts the module and its dependencies on a module path. Is it possible to change it to a classpath? 回答1: If you don't define a module-info, IDEA would set the application and your dependencies on the classpath. Since you have a module-info it's an explicit module so it has to be on the module path. Normally you would handle your dependecies now as automatic-modules. Howsoever, your dependencies at least have a good reason to be on the classpath. We discussed

Java 9 javapacker can't find jfxrt.jar while creating bss'. Seems totally broken in “createbss” mode under Linux. How to avoid the bug?

℡╲_俬逩灬. 提交于 2019-12-21 20:36:24
问题 I have Ubuntu Linux system with Sun JDE 9.0.1 and I need to convert some of Fx's CSS files to binary form from console. But when I execute the command: javapackager -createbss -outdir . -srcdir . I got an error: Error: jfxrt.jar needs to be on classpath for -createbss and for -createJar without -nocss2bin My JDK is properly installed. I have all necessary modules (including FX). Any ideas how I can avoid a stupid bug and I make the packager to do it's job? If I run javapackager from "/usr/lib

Compatibility and migration from Java 9 to Java 8

江枫思渺然 提交于 2019-12-21 12:55:43
问题 I'm reading the document about the new Java 9 module system. The paragraph 3 Compatibility & migration explains how to migrate code from Java 8 to Java 9, but says nothing on how "migrate" or run an application written in Java 9 to pre Java 9 runtimes. So, if I have, say a JAR application written in a modularity way (every module has a module descriptor) what does happen if I deploy it on, i.e, a JDK 8 runtime? 回答1: You cannot start a Java application with a JRE which is less than the one it

Create Module in JShell in Java 9

安稳与你 提交于 2019-12-21 10:17:25
问题 Just exploring new release of Java, its new module system, and playing with jshell as well. Probably my question doesn't have too much sense, but I am just curious. So I came up with the question: Is there any way to create a module in jshell? Or module can be only created in module-info.java ? 回答1: Modules cannot be created using JShell currently and it is not a Goal of JShell either. JShell Functionality The JShell API will provide all of JShell's evaluation functionality. The code

Is it possible to use dependencies without module-info.class in a Java 9 module

余生长醉 提交于 2019-12-21 07:40:11
问题 I created two small projects de.app1 and de.app2 , where App from de.app1 uses Test from de.app2 . ├── de.app1 │ ├── de │ │ └── app │ │ └── App.java │ └── module-info.java └── de.app2 └── de └── test └── Test.java module-info.java in the first project just contains module de.app1 {} I compiled the second project and created a jar file: javac de/test/Test.java jar cf app2.jar de/test/Test.class and then tried to compile the first project like this: javac -cp ../de.app2/app2.jar de/app/App.java

What do I need to build JDK 9 project with non-modular dependencies using Maven

五迷三道 提交于 2019-12-21 07:38:05
问题 I have a simple Java 9 SE project with one dependency on a non-modularized project (chose Weld SE for this example) and I am trying to build it with Maven ( clean install ).In order for Java 9 to kick in, I have added module-info.java . Originally, this file only contained module name and had no requires formulas. Please bear in mind that my sole dependency is NOT a modular project, therefore I presumed Maven will put in the classpath (not module-path) and hence it will end up in the unnamed

How to add “requires” for artifact having “-”(hyphen) in its name

寵の児 提交于 2019-12-21 07:08:20
问题 I've included these dependencies in my Maven pom.xml: <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>${httpclient.version}</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.4</version> </dependency> I am trying to add this dependency in module-info.java like so: module io.github.wildcraft.restclient { requires httpcore; // no compilation problem requires httpclient; // no

Java 9: What are collection factory methods? [closed]

最后都变了- 提交于 2019-12-21 06:41:16
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . The arrival of Java 9 brings many new features to Java's Collections API, one of which being collection factory methods. What are they and how can I implement them properly? 回答1: Note 1: To prevent the use of raw-types, I have opted to provide a generic type for each class that I