如在如何忽略系统默认区域设置以检索resourceBundle中所述,您可以在Java 8或更早版本中配置为不通过以下方式回退到默认区域设置:
ResourceBundle.getBundle("MyResources",
new Locale("en", "US"),
ResourceBundle.Control.getNoFallbackControl(ResourceBundle.Control.FORMAT_PROPERTIES))
Run Code Online (Sandbox Code Playgroud)
在Java 9 的ResourceBundle.Control使用抛出一个UnsupportedOperationException名为模块使用时:ResourceBundle.Control是不是在一个名为模块的支持.
如何实现/配置自定义"MyResourcesProvider [Impl]"以实现与ResourceBundle.Control.getNoFallbackControl提供的相同的行为?
我最近一直在读巴拿马项目.
我知道它将成为JNI的下一代替代品 - 它将允许Java开发人员使用Java在本机层上进行编码(这是令人惊叹的恕我直言).
从我所看到的jnr-posix看,用法很简单,例如:
public class FileTest {
private static POSIX posix;
@BeforeClass
public static void setUpClass() throws Exception {
posix = POSIXFactory.getPOSIX(new DummyPOSIXHandler(), true);
}
@Test
public void utimesTest() throws Throwable {
// FIXME: On Windows this is working but providing wrong numbers and therefore getting wrong results.
if (!Platform.IS_WINDOWS) {
File f = File.createTempFile("utimes", null);
int rval = posix.utimes(f.getAbsolutePath(), new long[]{800, 200}, new long[]{900, 300});
assertEquals("utimes did not return 0", 0, rval);
FileStat …Run Code Online (Sandbox Code Playgroud) 鉴于我不能将var用于不可表示的类型(Nulls,Anonymous Classes,Some Single Method Class,最重要的是相交类型).我最好不要使用它以获得更好的可读性和一致性(鉴于它仅适用于本地类型)?
我有点觉得它会被滥用,
__CODE__
我正在使用guava的ClassPath来检索可用的类.使用Java 8,这很好用,但我正在迁移到Java 10,现在它不起作用.我已经尝试了guava 24.1(Maven Central上可用的最新jar文件)和github上的最新资源(截至2018年4月27日) - 大概是或多或少的番石榴25.0,因为他们昨天发布了它.
我可以检索一些类,但任何java.*包中的任何内容都无法显示.这实际上是一个错误,还是我使用Java 10错误(即模块化意味着我需要做一些特别的事情)?我在Java 9中看到了相同的症状.我尝试使用Java 10(或9)构建和运行以及使用Java 8构建并使用Java 10(或9)运行,这两种行为都是相同的.
我已经建立了一个虚拟的例子,在封装两个类com.just.me和com.just.another:
package com.just.me;
import com.google.common.reflect.ClassPath;
import com.just.another.Dummy;
import java.lang.String;
import java.util.Collections;
import java.util.List;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
List<String> dummyList = Collections.emptyList();
printClassCount("com.just.me", Main.class);
printClassCount("com.just.another", Main.class);
printClassCount("com.just", Main.class);
printClassCount("com.google", Main.class);
printClassCount("java.lang", Main.class);
printClassCount("java.util", Main.class);
printClassCount("java", Main.class);
}
private static void printClassCount(String packageName, Class classForClassLoader) {
System.out.println("Number of toplevel classes in " + packageName …Run Code Online (Sandbox Code Playgroud) 我必须java.xml.ws*在我的项目中使用组件,但因为它已被弃用并且很快就会被删除我想要替换这些组件.所以我将这个依赖项添加到我的项目pom文件中:
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-ri</artifactId>
<version>2.3.0</version>
<type>pom</type>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这是我的模块配置:
module x.y.z {
requires kotlin.stdlib;
requires spring.boot;
requires spring.boot.autoconfigure;
requires spring.context;
requires cxf.core;
requires cxf.rt.frontend.jaxws;
requires java.xml.ws;
}
Run Code Online (Sandbox Code Playgroud)
但是有一个错误:
它是什么意思以及如何修复它以便我可以使用上面的依赖而不是java.xml.wsjdk?
我正在开发一个代码库,它使用JNI技术来构建本机方法.
以下是用于的本机对等方法的段 java.lang.String#equals(Object)
@MJI
public boolean equals__Ljava_lang_Object_2__Z (MJIEnv env, int objRef, int argRef) {
ElementInfo s1 = heap.get(objRef); // this
ElementInfo s2 = heap.get(argRef);
Fields f1 = heap.get(s1.getField("value")).getFields();
Fields f2 = heap.get(s2.getField("value")).getFields();
char[] c1 = ((CharArrayFields) f1).asCharArray();
char[] c2 = ((CharArrayFields) f2).asCharArray();
Run Code Online (Sandbox Code Playgroud)
这在Java 8上运行良好.但是在Java 9及更高版本中,valueString字段返回的值是char[]或者byte[]
我希望它返回一个byte []数组,因为在JEP 254:Compact Strings中进行了更改
例如:
char[] chars = new char[] {'a','b','c', 'd'};
String str1 = new String(chars))
"str2".equals(str1);
Run Code Online (Sandbox Code Playgroud)
在这里,我在对等方法中获取了char数组str1和字节数组"str2".这是因为字符串在堆中的存储方式不同吗?
供参考:
这是我正在实际工作的代码.我正在尝试使用Java 9及更高版本:
我有一个使用GWT-2.5.1和Java 8构建的大量Web应用程序。随着Java 8的弃用,我需要将其迁移到Java 10/11。
我已经设法解决了一些问题,但是我遇到了一个我无法解决的问题。
在构建应用程序时,出现以下错误:
[INFO] Compiling module com.<xxx>
[INFO] [ERROR] Unable to find type 'java.lang.Object'
[INFO] [ERROR] Hint: Check that your module inherits
'com.google.gwt.core.Core' either directly or indirectly (most often by
inheriting module 'com.google.gwt.user.User')
Run Code Online (Sandbox Code Playgroud)
查看gwt.xml文件,对我来说似乎正确:
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to="xxxx">
<inherits name="com.google.gwt.user.User" />
<inherits name="com.google.gwt.user.theme.clean.Clean" />
<inherits name="com.google.gwt.logging.Logging" />
<inherits name="com.XXXXCoreBase" />
<!-- Delete non-0inherits stuyff -->
</module>
<!-- XXXXCoreBase -->
<?xml version="1.0" encoding="UTF-8"?>
<module>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name="com.google.gwt.user.User" />
<inherits name="com.google.gwt.query.Query"/> …Run Code Online (Sandbox Code Playgroud) 我正试图从Java 8迁移到Java 10,并面临以下问题与JOOQ codegen Maven插件.
我的环境:
pom.xml中:
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.11.5</version>
<executions>
<execution>
...
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen</artifactId>
<version>3.11.5</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta</artifactId>
<version>3.11.5</version>
</dependency>
</dependencies>
<configuration>
<configurationFile>target/my_conf.xml</configurationFile>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
my_conf.xml如下所示:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.11.0.xsd">
<jdbc>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://${host}/${db_name}</url>
<user>${user_username}</user>
<password>${pwds}</password>
</jdbc>
<generator>
<database>
<name>org.jooq.meta.mysql.MySQLDatabase</name> …Run Code Online (Sandbox Code Playgroud) 我对此有麻烦,已经在本网站上回答过多次。
我对这个问题的看法有些不同。我有一个使用maven 3.5.x和java版本10(在maven-compiler-plugin中配置)可以很好地构建的项目。在IntelliJ的项目结构中查看时,所有模块的语言级别均为10(但项目设置为语言级别6,在项目结构中选择的SDK为1.8 ...
但是,即使我将sdk更改为java 10,并将项目语言级别更改为10,仍然会发生以下粘贴的错误... ????
我的IntelliJ版本:IntelliJ IDEA 2018.2.5
重现此错误:
GitHub:https : //github.com/jactor-rises/jactor-rises.git
尝试在IntelliJ中构建它:
信息:java:编译模块'jactor-commons'时发生错误信息:javac 10.0.1用于编译Java源信息:29/10/2018,21:31-编译在4 s 777中完成了1个错误和0个警告ms错误:java:不支持发行版本5
在发布时Java-11,当我们可以直接检查一个数字是否不为null或不等于特定数字时,为什么要orElseThrow与optionalLong/ OptionalDouble等Optional Types一起使用。
另外,我们正在做空检查,这比抛出异常更好吗?
可能是无法想象真正使用的optionalTypes和orElseThrow。
适用于的Javadoc orElseThrow。