Fragmented - Android Developer Podcast

031: Effective Java - Item 8


Listen Later

In this mini Fragment, we introduce Joshua's eighth Item. This one is a doozy, probably one of the longest items in the group of the effective Java series, but most definitely quite important.

This episode is brought to you by Rollbar. Go to rollbar.com/fragmented to get their Bootstrap plan for free for 90 days.

Stay tuned for more items from our "Effective Java for Android developers" Fragment series.

Show Notes
  • Effective Java (2nd Edition) - Joshua Bloch
  • Obey the general contract when overriding equals

    When to not override equals:
    • Each instance of the class is inherently unique.
    • You don't care whether the class provides a "logical equality" test.
    • A superclass has already overridden equals, and the superclass behavior is appropriate for this class.
    • The equals method implement an equivalence relation which states it must be:
      • Reflexive
      • Symmetric
      • Transitive
      • Consistent
      • For any non-null reference x, x.equals(null) must return false.
      • A recipe for a high-quality equals method is as such:
        • Use the == operator to check for references to this object.
        • Use the instanceof operator to check if the argument has the correct type 
        • Cast to the correct type.
        • Check all field types and corresponding field types.
        • Finally, when done, ask yourself - is this method symmetric, transitive and consistent?
        • Caveats
          • Always override hashcode when you override equals
          • Don't be too clever!
          • Don't substitute another type for Object in the equals declaration.
          • Contact
            • @fragmentedcast [twitter.com]
            • @donnfelker [twitter.com]
            • @kaushikgopal [twitter.com]
            • ...more
              View all episodesView all episodes
              Download on the App Store

              Fragmented - Android Developer PodcastBy Donn Felker, Kaushik Gopal

              • 5
              • 5
              • 5
              • 5
              • 5

              5

              68 ratings


              More shows like Fragmented - Android Developer Podcast

              View all
              Design Details by Brian Lovin, Marshall Bock

              Design Details

              361 Listeners

              Developer Tea by Jonathan Cutrell

              Developer Tea

              402 Listeners

              Does Not Compute by Sean Washington, Rockwell Schrock

              Does Not Compute

              53 Listeners

              Toolsday by Una Kravets, Chris Dhanaraj

              Toolsday

              48 Listeners

              Swift Unwrapped by JP Simard, Jesse Squires, Spec Network, Inc.

              Swift Unwrapped

              90 Listeners