Effective Java, even c# (2) Methods Common to All Objects

So GREAT The new version of Effective Java(2nd edition)  is! (Better than Effective c# 1 million times)

I’m reading this book and finding that lots of the skill can be used by other language programmers, especially c#’s.

This series of notes will cover the the things for both java and c#.

Wish you like it.

Methods Common to All Objects

  • Item 8: Obey the general contract when overriding equals

It’s not a new problem.

I don’t wanna repeat the detail of how to write your new equals method.

I just wanna notice the c# programmer: when you override the equals (and the == and != operators), you should implement the IEquatable interface as well.

  • Item 9: Always override hashCode when you override equals

Nothing to say.

  • Item 10: Always override toString

Do this. You will feel good when you debug your code.

  • Item 11: Override clone judiciously

Nothing to say.

  • Item 12: Consider implementing Comparable

Nothing to say.

The methods in the Object class look so identical in Java and c#. This is why someone said that the c# is a copy of Java.

All the problem above are discussed in CLR via c# very clearly. If you are a c# programmer. Read it. It will tell you something for c# only like Equals for struct etc.

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: