Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialEugene Paitoo
3,922 PointsA little help needed
I'm totally lost right from the beginning to the end of this video. i didn't get the whole video and please a little help will be appreciated.
Thanks very much! :)
1 Answer
michaelcodes
5,604 PointsHi there! I think the way that the concept is explained in the video is a bit confusing.
A couple of the main takeaways are that: It is generally better practice to use the .equals method rather than double equal signs (==) to check for equality. The reason for this is because in java the == does NOT check for equality when dealing with objects, only with primitives (integers, etc). All objects inherent from a generic object (known as "object"), meaning all objects can use the .equals method by default.
Even objects that you make yourself inherit from the generic object. There are many methods that objects inherit from the generic object, but for right now we are only concerned about the .equals method.
If you were to use:
object1 == object2
This checks that the objects reference the same location in memory.. This is most likely not what we are looking for (and will return false unless they are the SAME object) if we are trying to compare some value. To check for equality we use:
object1.equals(object2)
I hope this helps a bit, these are some main points the video was trying to convey, if you have any other questions don't hesitate to ask! Also don't feel discouraged if you don't immediately understand it, I know it can be confusing and digesting it over a couple days really helps! Take care and happy coding :)
Pedro Cabral
33,586 PointsPedro Cabral
33,586 PointsI would also like to add that the benefit comes from overriding the .equals method with the author's own notion of equality, otherwise the method just ends up behaving like a "==" since it returns true if the calling object is the same as the object passed into the argument. Also, I believe the word "thing" in the topic of the workshop, refers to the String pooling/interning which is a different thing all together. But understanding the concept that michaelcodes wrote comes first as "the thing about Strings" (pooling/interning) builds upon that.
Eugene Paitoo
3,922 PointsEugene Paitoo
3,922 PointsThanks very much. i'm still a code newbie though so sometimes getting a hold these stuff takes time, i don't know how you guys did it to reach so level of proficiency but anyways I'm much grateful for the answer. :)