17 February 2012

Reinventing the wheel: Collection.size()

 Original way to reinvent the wheel - by an examination of "Programming Fundamentals"
 
public class MyContainer {
   private final Collection myBag;

   public int getBagSize() {
    int j = 0;
    for(int i = 0; i < this.myBag.size(); i++) {
     j++;
    }
    return j;
   }
}

1 comment:

  1. Mamma mia che bomba! Però volevo complimentarmi per l'utilizzo di final...

    ReplyDelete