我经常使用Eclipse的代码生成工具(Source/Generate hashCode()和equals()...)来为简单的POJO类创建equals()实现.如果我选择"使用instanceof来比较类型",则会生成类似于此的equals()实现:
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof MyClass)) {
return false;
}
MyClass other = (MyClass) obj;
// check the relevant fields for equality
}
Run Code Online (Sandbox Code Playgroud)
今天一位同事指出,第二个if语句根本不是必需的,因为只要obj为null,类型检查的instanceof就会返回false.(见问题3328138.)
现在,我想那些为Eclipse JDT编写代码模板的人也值得他们的盐.所以我认为这个空检查必须有一些原因,但我不确定它是什么?
(还有问题7570764可能会给出一个提示:如果我们使用getClass()比较进行类型检查而不是instanceof,obj.getClass()不是null安全.如果我们使用instanceof,可能代码模板不够聪明,不能忽略null检查.)
编辑:Dragan在他的回答中注意到,类型检查的instanceof不是Eclipse中的默认设置,所以我编辑了这个问题.但这并没有改变任何事情.
另外请不要建议我使用getClass()或(甚至更好!)一个不同的IDE.这不是重点,不能回答这个问题.我没有询问有关如何编写equals()实现的建议,无论是使用instanceof还是getClass()等.
问题大致是:这是Eclipse中的一个小错误吗?如果不是,那为什么它有资格成为一个功能?
我有一个包含数据的clob
<?xml version='1.0' encoding='UTF-8'?><root available-locales="en_US" default-locale="en_US"><static-content language-id="en_US"><![CDATA[<script type="text/javascript">
function change_case()
{
alert("here...");
document.form1.type.value=document.form1.type.value.toLowerCase();
}
</script>
<form name=form1 method=post action=''''>
<input type=text name=type value=''Enter USER ID'' onBlur="change_case();">
<input type=submit value=Submit> </form>
</form>]]></static-content></root>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我想用onblur提取线
<input type=text name=type value=''Enter USER ID'' onblur="change_case();">
Run Code Online (Sandbox Code Playgroud) 有没有办法在 IntelliJ IDEA 2018.1 中创建空提交(即没有实际更改)(使用 git 和 Git 集成插件)?
我正在寻找相当于
git commit --allow-empty -m "foo"
Run Code Online (Sandbox Code Playgroud)
但使用GUI。
尝试提交空的更改列表只会产生“未检测到更改”的错误消息。
我尝试在 chrome 中运行 xml/xsl(它适用于 firefox)但我有这个错误:
不安全的尝试从带有 URL file:///C:/Users/..../thing.xml 的框架加载 URL file:///C:/Users/..../thing.xsl。'file:' URL 被视为唯一的安全来源。
我该如何解决?我在互联网上找到的解决方案很少,但没有任何效果(--allow-file-access-from-files 不起作用)。
我们的团队最近在 Jenkins 插件管理器安装/更新插件时遇到了一些问题。在我们修复了防火墙和代理规则的一些问题(我们位于公司防火墙和代理之后)之后,我们仍然无法下载一些插件文件。
一些插件文件已成功下载并安装,另一些则因以下错误而失败:
Failed to install git-client
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:735)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1593)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:3057)
at java.net.URLConnection.getHeaderFieldLong(URLConnection.java:629)
at java.net.URLConnection.getContentLengthLong(URLConnection.java:501)
at java.net.URLConnection.getContentLength(URLConnection.java:485)
at hudson.model.UpdateCenter$UpdateCenterConfiguration.download(UpdateCenter.java:1161)
Caused: java.net.SocketTimeoutException: Read timed out
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1950)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1945)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1944)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1514)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
at hudson.model.UpdateCenter$UpdateCenterConfiguration.download(UpdateCenter.java:1177)
Caused: java.io.IOException: Failed to load http://updates.jenkins-ci.org/download/plugins/git-client/3.0.0/git-client.hpi …Run Code Online (Sandbox Code Playgroud)