ZoneId.of("UTC")而不是ZoneOffset.UTC?我们知道两者之间的区别,如ZoneOffset.UTC 和 ZoneId.of("UTC") 之间的区别是什么?。
<tl;博士>版本:
ZoneOffset.UTCZoneOffset返回ID 为“Z”、偏移量为 0 和默认区域规则的meme 。ZoneId.of("UTC")返回ZoneRegionID 为“UTC”并ZoneOffset.UTC包含在内。</tl;博士>
对于这个问题,我假设使用 UTC 仅仅是为了更容易处理日期和时间,而不是因为某些东西实际上可能位于 UTC 区域或其他一些业务原因将其作为实际的 ZoneRegion。
例如,在处理ZonedDateTime. 我发现的唯一区别是它的打印方式不同。
2021-06-10T15:28:25.000000111Z
2021-06-10T15:28:25.000000111Z[UTC]
Run Code Online (Sandbox Code Playgroud)
我们正在就这个问题来回进行代码审查讨论,所以我想这种冲突并不罕见。
ZoneOffset.UTCZoneId.of("UTC")ZoneId.of("UTC")只是一个区域环绕ZoneOffset.UTC,到目前为止我找不到任何好处。据我所知,在 UTC 中,除了继承的ZoneOffset.UTC规则之外,不存在与区域相关的数据。除非您出于某些(例如商业)原因确实需要 UTC 时区/地区,否则您应该更喜欢ZoneOffset.UTC. 它在性能足迹方面有一个(较小的)优势,而 UTC ZoneRegion 似乎没有提供任何我能看到或想到的好处。
然而,由于 Java Date …
根据新发布的JUnit 5.2版,现在有一个BOM:
JUnit BOM:为了简化使用Maven或Gradle的依赖管理,现在在org.junit:junit-bom:5.2.0 Maven坐标下提供了物料清单POM。
首先,目前我的POM如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bosspanda.tmp</groupId>
<version>0.1-SNAPSHOT</version>
<artifactId>tmp</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>10</maven.compiler.target>
<java.version>10</java.version>
<junit.version>4.12</junit.version>
<junit.jupiter.version>5.2.0</junit.jupiter.version>
<junit.vintage.version>5.2.0</junit.vintage.version>
<junit.platform.version>1.2.0</junit.platform.version>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.vintage.version}</version>
<scope>test</scope>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
如果我正确地理解了上面的BOM表发行说明,那就是将这个junit <dependency>标签简化为单个BOM表依赖项。
但是,我在将其集成到项目的pom.xml中时遇到了麻烦。在查看了链接的资源(https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies)后,我得出结论,我必须用单:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.2.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
但是有了这个,IntelliJ IDEA(v。2018.1.3 …
大多数静态代码分析工具建议不要捕获一般(特别是未经检查的)异常,如RuntimeExceptions和Errors.
除非此异常障碍在顶层可能是合理的,否则通常不会处于较低级别.不幸的是,在重写/修复现有代码时,这很难实现,因为可能的错误和RuntimeExceptions的潜在可能性可能过高.此外,挖掘较低的代码级别来获取一些合理的Exceptions概念以捕获而不是通用catch,这实际上是一个非常耗时且复杂的任务.
您是否知道将这些通用(未经检查)的异常解释为更具体的异常的任何工具或最佳实践?
说我们有类似的东西:
try
{
somethingReallyComplex();
}
catch (RuntimeException | Error ex)
{
Logger.error(this, ex.getClass().getName() + " while doing something really complex", ex)
}
Run Code Online (Sandbox Code Playgroud)
try块可以包含一个非常复杂的代码问题,其中包含各种不同的RuntimeExceptions和Errors,这些都是有意义的.但是,如何最有效地分析此代码以将RuntimeException解析为NullPointerException,ArrayIndexOutOfBoundException ...无论什么可能合理?
是否有任何工具可以分析此类代码并提供有关大多数常见RuntimeExceptions的建议等等?
你是如何开始解决这个问题的?
主观或客观"阈值"在哪里说:"不,我只是把它作为RuntimeException并添加一个抑制注释?"
我在Python 2.7(Win 8.1 x64)上,我想在Chrome中打开一个URL.由于Chrome仅在3.3+本机支持,我正在尝试通用调用:
import webbrowser
webbrowser.get("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %s").open("http://google.com")
Run Code Online (Sandbox Code Playgroud)
路径是正确的,打印确实给我一个处理程序:
"<webbrowser.GenericBrowser object at 0x0000000002D26518\>"
Run Code Online (Sandbox Code Playgroud)
但是,open() - 最好是open_new_tab()) - 函数不起作用.它返回False.
如果我运行命令
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "https://google.com"
Run Code Online (Sandbox Code Playgroud)
在Windows运行对话框中,它确实可以正常工作.
如果我将Chrome设置为标准浏览器并运行
webbrowser.get().open("http://google.com")
Run Code Online (Sandbox Code Playgroud)
它确实有效,但它不是我想要的.
有谁知道出了什么问题?