我正在使用Java 13(13.0.1.hs-adpt),并且启用了预览语言功能(主要是由于文本块)。
我的代码会在适当的@SuppressWarnings("preview")地方加上适当的注释,但是我仍然可以
Note: Some input files use preview language features.
Note: Recompile with -Xlint:preview for details.
Run Code Online (Sandbox Code Playgroud)
每当我编译时。
我知道那不是编译器打印警告(实际上,-Xlint:-preview不会更改任何内容)。
有没有办法抑制这些消息?
我已经找到的所有文档都提到了“ jre / lib / ext”文件夹,但是在我的JRE 13安装中不存在。
我猜在Java 8(可以在jre / lib / ext中看到罐子)和Java 13之间的某个地方,它们移动了,但是我无法确定何时以及如何完成。
有人可以根据扩展类当前所在的位置来详细说明新JRE的情况吗?
我有点使用以下源来创建我自己的 sdf 模式:https : //docs.oracle.com/en/java/javase/13/docs/api/java.base/java/text/SimpleDateFormat.html
很遗憾
SimpleDateFormat mFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
...
private Date getLatestTimeStamp() throws ParseException {
return mFormatter.parse("Mon, 19 Dec 2019 11:32:04 +0000");
}
Run Code Online (Sandbox Code Playgroud)
导致以下错误,我不明白为什么:
java.text.ParseException: Unparseable date: "Mon, 19 Dec 2019 11:32:04 +0000"
Run Code Online (Sandbox Code Playgroud)
任何帮助都是极好的!
编辑:我正在使用 JDK 13
编辑2:
因此,我清理了我的代码,创建了一个新项目,但它仍然无法正常工作:
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
public class Main {
public static void main(String[] args) {
String source = "Thu, 19 Dec 2019 11:32:04 +0000";
DateTimeFormatter mFormatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss Z"); …Run Code Online (Sandbox Code Playgroud) JSP 和 html 文件由 NetBeans 中的 Glassfish 服务器提供服务,但不提供 servlet。最新的 NetBeans 配置为使用最新的 JDK 13,而 Glassfish 使用的是 Java EE 1.8
浏览器报错:
HTTP Status 500 - Internal Server Error
type Exception report
message
Internal Server Error
description
The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Error instantiating servlet class com.example.NewServlet
root cause
com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class com.example.NewServlet
root cause
java.lang.RuntimeException:
note The full stack traces of the exception and its root causes …Run Code Online (Sandbox Code Playgroud) 任何人都可以解释为什么removeRange(int fromIndex, int toIndex)在 Java Vector 中受到保护?
句法 -
protected synchronized void removeRange(int fromIndex, int toIndex)
我研究了一些博客并做了一些代码来理解,但这里的事情并不是很清楚。我已经查看了 Vector.java 并尝试创建一些理解。但我的总体看法是removeRange(int fromIndex, int toIndex)最终会被删除。
我觉得sublist(int fromIndex, int toIndex).clear()有能力做同样的工作。从实现和可用性的角度来看,看起来更合适。
如果您有更好的想法,请帮助理解。
我刚刚尝试了Java 13中的新文本块功能,但遇到了一个小问题。
我已经从Jaxcenter阅读了这篇文章。
右三引号将影响格式。
String query = """
select firstName,
lastName,
email
from User
where id= ?
""";
System.out.println("SQL or JPL like query string :\n" + query);
Run Code Online (Sandbox Code Playgroud)
上面的格式效果很好。为了与结束定界符(“”“)对齐,多行字符串在每行之前保留空格。
但是,当我尝试比较以下两个文本块字符串时,它们在输出控制台中的格式相同,但是即使在之后也不相等stripIntent。
String hello = """
Hello,
Java 13
""";
String hello2 = """
Hello,
Java 13
""";
System.out.println("Hello1:\n" + hello);
System.out.println("Hello2:\n" + hello);
System.out.println("hello is equals hello2:" + hello.equals(hello2));
System.out.println("hello is equals hello2 after stripIndent():" + hello.stripIndent().equals(hello2.stripIndent()));
Run Code Online (Sandbox Code Playgroud)
输出控制台类似于:
String query = """
select firstName,
lastName,
email …Run Code Online (Sandbox Code Playgroud) 有没有办法让Eclipse了解Java 13功能,例如文本块?Eclipse报告以下代码的错误:
class Main {
private String text = """
first line
second line
third line
""";
}
Run Code Online (Sandbox Code Playgroud)
错误包括:
first cannot be resolved to a type
Duplicate field Main.line
Run Code Online (Sandbox Code Playgroud)
我怀疑问题是通常是Eclipse和Java 13的结合。
使用Maven构建成功(使用适当的--enable-preview配置)。使用的“已安装JRE”是Java 13(具有--enable-preview默认的VM参数)。安装对Eclipse 2019-09的Java 13支持似乎也无济于事(不添加Java 13合规性级别选项)。
这个问题与使用 Java 反射更改私有静态最终字段密切相关。在那里,有人问,如何改变一个private static final变量。
但是,该问题的答案在 Java 12+ 中不起作用,因为您无法访问java.lang.reflect.Field使用反射的私有变量。
尽管如此,当您尝试这样做时,您最终会得到如下堆栈跟踪:
Exception java.lang.NoSuchFieldException: modifiers
at Class.getDeclaredField (Class.java:2412)
at <your call of Field.class.getDeclaredField("modifiers").setAccessible(true)>
Run Code Online (Sandbox Code Playgroud)
有没有办法在这些版本中更改这样的常量?
我可以想象使用 JNI/JNA 是可能的。
我注意到String.replace(CharSequence, CharSequence)java 12 和 13 之间的行为有所不同。
java 12 及更早版本:
System.out.println("String"=="String".replace("g","g")); //false
Run Code Online (Sandbox Code Playgroud)
Java 13 及更高版本:
System.out.println("String"=="String".replace("g","g")); //true
Run Code Online (Sandbox Code Playgroud)
发现这可能是由于:
针对常见情况优化 String.replace(CharSequence, CharSequence)
这是意外行为吗?
是的,我知道 equals 方法。
试图理解 switch 表达式并想出了以下代码。事实上,对于所有“break - String”组合,我都会收到“not a statement”错误。我究竟做错了什么?
String i = switch(value) {
case 0:
break "Value is 0";
case 1:
break "Value is 1";
case 2:
break "Value is 2";
default:
break "Unknown value";
};
Run Code Online (Sandbox Code Playgroud) 在 Eclipse 编译器窗口中,Java 13未显示。
如何在 Eclipse 中启用 JDK 合规性级别 13。
java-13 ×11
java ×10
eclipse ×2
string ×2
classloader ×1
classloading ×1
collections ×1
constants ×1
glassfish ×1
ide ×1
java-12 ×1
javac ×1
jls ×1
netbeans ×1
reflection ×1
replace ×1
servlets ×1
unparseable ×1