Coding is fun. Really :D

I used to put some stupid test cases to unit-test my code and I usually don’t forget to remove ’em before review. But last time when my customer reviewed my code, he found the following segment at the end of a Java file. He laughed and asked “Is that true Subin?” 😀

//------------------------ Test methods ---------------------------

static class TestClass
{
 public TestClass(String name)
 {
 this.name = name;
 }

 private String name;

 @Override
 public boolean equals(Object anObject)
 {
 return (true);
 }

 @Override
 public int hashCode()
 {
 return (1);
 }
}

public static void main(String[] args)
{
 Set<TestClass> aSet = new HashSet<TestClass>();
 aSet.add(new TestClass("Subin "));
 aSet.add(new TestClass("is in "));
 aSet.add(new TestClass("a "));
 aSet.add(new TestClass("big "));
 aSet.add(new TestClass("big "));
 aSet.add(new TestClass("trouble"));

 System.out.println(aSet.size());
}
Advertisements