- 浏览: 71945 次
- 性别:
- 来自: 北京
文章分类
最新评论
Why a trap ?
First ,let's take a look at the comments of this API provided by Sun:
/**
* Returns the same hash code for the given object as
* would be returned by the default method hashCode()
,
* whether or not the given object's class overrides
* hashCode().
* The hash code for the null reference is zero.
*
* @param x object for which the hashCode is to be calculated
* @return the hashCode
* @since JDK1.1
*/
public static native int identityHashCode(Object x);
Pls,pay more and more attention to the default method hashCode() , do you know what is the default method hashCode()?? It is the hashCode() defined in Object class !!!
i.e. the one public native int hashCode(); The most confusing comment is “whether or not the given object's class overrides hashCode()" , this is definitely bullshit bullshit.....
That means if your class overrides hashCode(), System.identityHashCode() != your.hashCode()! Checkout below testcase:
import junit.framework.TestCase; public class TestIdentityHashCode extends TestCase{ public void testIdentityHahshCodeAlwaysReturnTheSameAsDefaultHashCode() { Object arbitaryObj = new Object(); assertEquals(arbitaryObj.hashCode(),System.identityHashCode(arbitaryObj)); ObjectWhichDoesNotOverrideHashCode objUsingDefaultHashCode = new ObjectWhichDoesNotOverrideHashCode(); assertEquals(objUsingDefaultHashCode.hashCode(),System.identityHashCode(objUsingDefaultHashCode)); ObjectWhichOverrideHashCode objUsingOverridedHashCode = new ObjectWhichOverrideHashCode(); assertEquals(objUsingOverridedHashCode.hashCode(),System.identityHashCode(objUsingOverridedHashCode)); } public void testIdentityHashCodeOfNullIsZero() { assertEquals(0, System.identityHashCode(null)); } private static class ObjectWhichDoesNotOverrideHashCode { } private static class ObjectWhichOverrideHashCode { public int hashCode() { return 1000; } } } Above testcase always fails as expected.. so pls pay attention the trap . BTW: the default hashCode() of Sun's JVM always returns the memory address of the specific Object which guarantee it's unique. So System.identityHashCode() could be used to generate a unique key in a same JVM.
发表评论
-
How to be a Programmer: A Short,Comprehensive,and Personal Summary
2013-10-28 10:38 587well written. http://samizdat ... -
js module pattern
2013-10-12 16:21 398http://www.adequatelygood.com/ ... -
GZip compressing HTML, JavaScript, CSS etc. makes the data sent to the browser s
2013-07-31 15:48 660this is fun. http://tutorials ... -
java collection matrix
2012-08-07 11:24 745http://www.janeve.me/articles/w ... -
ghost text (aka in-field text)
2012-04-01 11:18 697http://archive.plugins.jquery.c ... -
What is Optimistic Locking vs. Pessimistic Locking
2011-09-09 16:50 834What is Optimistic Locking vs. ... -
what is DAO
2011-04-15 13:42 768http://java.sun.com/blueprints/ ... -
indenting xml in vim with xmllint
2011-01-10 09:48 708I added to my “.vimrc” file: ... -
css sprite
2010-12-15 16:57 665http://css-tricks.com/css-sprit ... -
最牛B 的 Linux Shell 命令
2010-10-30 00:08 714http://hi.baidu.com/hy0kl/blog/ ... -
GPS Bearing VS Heading
2010-10-21 15:40 1675http://gps.about.com/od/glossar ... -
Document Type Declaration
2010-07-19 22:01 833Document Type Declaration h ... -
XML Declaration must be the first line in the document.
2010-06-12 17:54 901The XML declaration typically a ... -
UCM
2010-05-08 11:41 745Two links about UCM The power ... -
What is an MXBean?
2010-01-28 11:10 763refer to http://weblogs.java. ... -
why wait() always in a loop
2010-01-19 00:17 843As we know ,jdk API doc suggest ... -
Locks in Java
2010-01-18 22:48 936copied from http://tutorials.je ... -
use jps instead of ps to find jvm process
2010-01-11 14:21 817copied from http://java.sun.com ... -
My first error of Hello Wolrd Struts
2010-01-04 09:10 866It's my first time to touch Str ... -
Unit Testing Equals and HashCode of Java Beans
2009-12-29 10:07 1309copy from http://blog.cornetdes ...
相关推荐
Trap+Instrumental.lnk
SnmpTrap 是 SNMP 协议的一部分,它允许网络设备在发生特定事件时发送报警或陷阱消息到预先配置的管理站。这篇文章将详细介绍如何使用 SnmpTrap 工具,并探讨其相关知识点。 首先,我们需要理解 SnmpTrap 的基本...
《为使用SNMP定义Trap的惯例 (RFC1215)》是一份关于网络管理的文档,由M. Rose编辑,旨在提供一种定义SNMP(简单网络管理协议)陷阱的标准方法。SNMP是一种广泛用于监控网络设备状态和性能的协议。陷阱(Trap)是...
LEON 2 SystemC model on ReSP, 21页,目录如下: 1 Leon 2 5 1.1 Introduction . . . . . . . ....1.2 Architecture Description ....2.5 Modication of RTEMS to enable interrupts trap handler . . . . 20
在SNMP中,SNMPtrap是一个关键功能,它允许网络设备在发生特定事件时主动向网络管理员或管理系统报告,而无需等待轮询。SNMPtrap消息是设备向管理站发送的异步通知,这些通知通常与设备故障、状态变化或其他重要事件...
"snmptrap.zip"这个压缩包显然包含了用于在Windows环境下接收和调试SNMP TRAP信息的工具。 **SNMP TRAP详解:** SNMP TRAP是一种异步通信机制,当网络设备遇到异常情况或者发生了预定义的事件(如接口故障、内存...
本文将详细介绍SNMP实例,特别是通过Java库snmp4j实现的GET、GETNEXT、SET操作以及TRAP发送和MIB获取。 1. **SNMP基本概念** SNMP由三个主要组件构成:管理站(Manager)、代理(Agent)和管理信息库(MIB)。管理...
So, while dedication and hard work are commendable qualities, it's vital to strike a balance and avoid falling into the trap of workaholism. After all, life is not just about work; it's about living, ...
It approaches bioinformatics from a unique perspective, highlighting interdisciplinary gaps that often trap the unwary.The book considers how the need for biological databases drove the evolution of ...
1 The Business of NAND. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Rahul N. Advani 2 Reliability of 3D NAND Flash Memories. . . . . . . . . . . . . . . . . . . . 29 A. Grossi, C...
- **程序方式发送Trap**:对于某些特定需求,可以编写C语言程序,使用SNMP库(如`send_easy_trap`或`send_v2trap`)发送Trap。 2. **Manager 端配置**: - **配置 snmptrapd.conf**:设置访问权限,添加Trap...
`snmp_trap`协议接收工具是针对SNMP Trap消息设计的应用,允许用户在Windows、Linux和Unix系统上接收并处理这些 traps。 SNMP Trap工作原理: 1. 设备触发事件:当网络设备(如路由器、交换机或服务器)遇到预定义...
Console.WriteLine($"Trap received from {trap.SrcAddress}"); foreach (var variable in trap.Vars) { Console.WriteLine($"OID: {variable.Oid}, Value: {variable.Value}"); } } } ``` 6. **配置网络设备...
6Existence and uniqueness of the MP inverse . . . . . . . . . . . 37viContents 7Some properties of the MP inverse . . . . . . . . . . . . . . . . 38 8Further properties . . . . . . . . . . . . . . . ....
"receive_trap.exe"文件是一个可执行文件,双击运行后,该软件会在后台监听SNMP Trap消息。当你在其他设备上触发一个Trap命令时,这个软件将捕获并显示相关信息,从而帮助你验证Trap消息是否成功发送和接收。 在...
Most SNMP traps sent to trap.coldstart.io will arrive on your phone within 500ms, with a crowd sourced human readable version of the OIDs in a manner similar to SNMPTT. Read more here: ...
"When you have learned to snatch the error code from the trap frame, it will be time for you to leave." “当你从我手中夺走水晶球时,就是你离开的时候了。” 1.1 Something mysterious is formed, born ...
SNMPTrap是SNMP的一部分,用于设备向管理系统发送通知,通常在设备状态发生变化时,如接口状态改变或硬件故障等。在Java中实现SNMP通信,SNMP4J是一个常用的库。 《java_conn_SNMPtrap_send_accept.rar》这个压缩包...
SNMP陷阱是一种主动的通知机制,当网络设备发生异常或需要报告特定事件时,设备会向管理站发送trap,从而让管理员能够及时响应。 SNMP协议定义了五种版本:SNMPv1、SNMPv2c、SNMPv3、SNMPv2u和SNMPv2t。在这个场景...
本项目"mpi_trap1.rar"聚焦于使用MPI(Message Passing Interface)来实现梯形积分法的并行化,从而加速计算过程。 MPI,全称Message Passing Interface,是一种标准的库,用于在分布式内存系统(如多核处理器、...