Skip to main content
0 online
theremin May 3, 2006

Quite a lot to do with this one.. so Far I have a class that looks like public class Person { private String firstName; private String lastName; public Person() { firstName = ""...

iwz May 3, 2006

Well, here's something to get you started: "So how would I set the last name only" q[Person person = new Person(); person.setLastName("Smith");]q or q[Person person = new Person(null, "Smi...

theremin May 3, 2006

That is kind. Thank you.

iwz May 3, 2006

here's a bonus equals method you can add to the Person class: q[public boolean equals( Object o ) { if ( this == o ) return true; if ( o == null || getClass() != o.getClas...

theremin May 3, 2006

Well this is what I did.. tell me if it looks right. It compiles without errors at least. hehe public class Person { private String firstName; private String middleName; private String ...

dgiaimo May 3, 2006

Your equals method shouldn't throw an Exception if you pass in null, as this one will.

deanh77 deanh77Founder

yes check that the otherPerson is null, and return false if it is. and use .equals on Strings like Ian said, since == is a reference equality in objects (i.e. these two variables point to the same object in memory), but String's equals() does an equality check on the contents of the Object (the internal array of characters that make up the String).

Welcome Back to eZabel

It's been a while. Here's what's new.

eZabel Lore

A complete history of our community — stats, Hall of Fame, legendary threads, and more.

View the Lore →

Everything Preserved

All 225,969 pieces of content from 2000–2014 are here — forums, messages, journals, photos, polls, and events.

💎

Gems

Spot something you love — a legendary comment, a classic thread, a great photo? Log in and click the diamond icon to mark it as a Gem. Add a note about why it's special. The best stuff surfaces on the Gems page.