Java CellStyle共享相同的堆地址ApachePOI

Java CellStyle共享相同的堆地址ApachePOI,java,apache-poi,heap-memory,Java,Apache Poi,Heap Memory,当我在ApachePOI中使用CellStyle创建新的cellstyles时,两个样式对象似乎共享相同的堆内存地址 怎么可能呢 请查看以下示例: CellStyle style1 = workbook.createCellStyle(); CellStyle style2 = workbook.createCellStyle(); 当我调试代码时,style1和style2与org.apache.poi.xssf.usermodel具有相同的内存地址。XSSFCellStyle@a140

当我在ApachePOI中使用
CellStyle
创建新的cellstyles时,两个样式对象似乎共享相同的堆内存地址

怎么可能呢

请查看以下示例:

CellStyle style1 =  workbook.createCellStyle();
CellStyle style2 =  workbook.createCellStyle();
当我调试代码时,
style1
style2
org.apache.poi.xssf.usermodel具有相同的内存地址。XSSFCellStyle@a1409f7c

有人能解释一下这种奇怪的行为吗

多谢各位
Aswini J

org.apache.poi.xssf.usermodel。XSSFCellStyle@a1409f7c
您观察到的不是内存地址,也不是类似的地址,而是对象类的toString()方法

toString()的默认实现是
classname@hashcode


很明显,您使用默认构造函数实例化了两个对象,使它们具有相同的状态。因此hashCode()的默认实现将为这两个不同的对象提供相同的哈希代码。它们具有相同的类和hashcode,因此产生
classname@hashcode
是相同的。

org.apache.poi.xssf.usermodel。XSSFCellStyle@a1409f7c
您观察到的不是内存地址,也不是类似的地址,而是对象类的toString()方法

toString()的默认实现是
classname@hashcode

很明显,您使用默认构造函数实例化了两个对象,使它们具有相同的状态。因此hashCode()的默认实现将为这两个不同的对象提供相同的哈希代码。它们具有相同的类和hashcode,因此产生
classname@hashcode
是相同的