<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Java on 予而不语</title>
    <link>https://heiybb.com/tags/java/</link>
    <description>Recent content in Java on 予而不语</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Fri, 26 Oct 2018 04:39:00 +0000</lastBuildDate><atom:link href="https://heiybb.com/tags/java/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Notes about the hashCode &amp; equals</title>
      <link>https://heiybb.com/posts/hashcode/</link>
      <pubDate>Fri, 26 Oct 2018 04:39:00 +0000</pubDate>
      
      <guid>https://heiybb.com/posts/hashcode/</guid>
      <description>import java.util.HashSet; import java.util.Set; public class HashEqualTest { public static void main(String[] args) { Set&amp;lt;Foo&amp;gt; fooSet = new HashSet&amp;lt;&amp;gt;(); Foo f1 = new Foo(1); Foo f2 = new Foo(1); Foo f3 = new Foo(1); Foo f4 = new Foo(1); fooSet.add(f1); fooSet.add(f2); fooSet.add(f3); fooSet.add(f4); System.out.println(fooSet.size()); System.out.println(&amp;#34;Break Point&amp;#34;); // only the first one element will be stored } } /** * result * * the add method will check the hashCode first * when the hashCode is the same the the equals method will be call * to compare the two instance * * if the hashCode is not override then the hashCode compare return false * the equals will no be called * * override the equals method is strongly not recommended * in order to avoid some unpredictable issues * * * when override the equals method, parameter &amp;#39;Object&amp;#39; type required * not the specific type */ class Foo { private int f; Foo(Integer x) { this.</description>
    </item>
    
  </channel>
</rss>
