我正在使用java 11使用一些依赖项和编译到旧版本.我将一个依赖项迁移到Java 11并且工作正常,但我们仍然必须在Java8上运行Tomcat 7或8.是否有可能使用--release标志来编译它使用的代码var,stream().dropwhile(...)或Map.of(...)和8上运行?
发布标志表明它应该是可能的:
--release release针对特定VM版本的公共,支持和记录的API进行编译.支持的发布目标是6,7,8和9.
这个项目是一个依赖项,独立于SprinBoot2.1和Java11可以正常工作,但需要在Java8中运行.
我的maven插件编译器设置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>8</release>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但是这禁止编译> jdk8特定代码.我正在使用上面最新的maven 3.6.0和mvn编译器.
尝试编译:
return List.of("dsadas", "dasdadddds", "£dsada", "dasdas")
.stream()
.dropWhile(s -> s.contains("das"))
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
抛出错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project api: Compilation failure: Compilation failure:
[ERROR] /home/agilob/Projects/.....java:[58,13] cannot find symbol
[ERROR] symbol: class var
[ERROR] location:
[ERROR] /home/agilob/Projects/....java:[43,20] cannot find symbol
[ERROR] symbol: method of(java.lang.String,java.lang.String,java.lang.String,java.lang.String)
[ERROR] location: interface java.util.List
[ERROR] -> …Run Code Online (Sandbox Code Playgroud) 我正在进行内部实现.System.out.println()尽管我理解这是如何工作但却无法弄清楚:
System课程.他们可以直接使用包中PrintStream存在的类io.
语法的意义是什么className.referenceVariable.Methodname,因为我们通常不使用它.这有什么具体原因吗?
任何人都可以详细说明这些要点或任何相关信息都会很棒.
时间代码执行可能很方便,所以您知道事情要花多长时间。但是,我发现这样做的一般方法很草率,因为它应该具有相同的缩进,这使得读取实际计时内容变得更加困难。
long start = System.nanoTime();
// The code you want to time
long end = System.nanoTime();
System.out.printf("That took: %d ms.%n", TimeUnit.NANOSECONDS.toMillis(end - start));
Run Code Online (Sandbox Code Playgroud)
我提出以下内容,它看起来更好,但有一些优点和缺点:
好处:
缺点:
AutoClosable应该使用的方式(很确定)TimeCode不好的新实例try块内声明的变量不能在块外访问可以这样使用:
try (TimeCode t = new TimeCode()) {
// The stuff you want to time
}
Run Code Online (Sandbox Code Playgroud)
使之成为可能的代码是:
class TimeCode implements AutoCloseable {
private long startTime;
public TimeCode() {
this.startTime = System.nanoTime();
}
@Override
public void close() throws Exception {
long endTime = …Run Code Online (Sandbox Code Playgroud) 我想把状态传给兄弟姐妹甚至是祖父母.
我有3个组件.在里面Header,我有一个带有onClick功能的按钮,可以在里面切换下拉菜单Navigation.顺便说一下,我想通过相同的状态AnotherComponent.
如何将状态(如isDropdownOpened)传递Header给Navigation和AnotherComponent?
<div>
<Header />
<Navigation />
<div>
<div>
<div>
<AnotherComponent />
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我不明白为什么变量initialCoordinates正在改变.当我运行程序时,initialCoordinates在每次循环运行后更改值.
int[] initialCoordinates = { 26, 0 };
int[] positions = { 1, 2, 3, 4 };
int[][] coordinates = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } };
for (int i = 0; i < 4; i++) {
System.out.println("Initial: " + initialCoordinates[1]);
coordinates[i] = initialCoordinates;
coordinates[i][1] += positions[i];
}
Run Code Online (Sandbox Code Playgroud) 我想删除文件的扩展名。例如:
ActualFile = image.pngExpectedFile = image使用哪种方法最有效?
removeExtension()org.apache.commons.io 提供的方法fileName.substring(0, fileName.lastIndexOf('.'))java ×5
class ×1
gatsby ×1
javascript ×1
maven ×1
println ×1
printstream ×1
reactjs ×1
system.out ×1
timing ×1