Key and value, yin and yang, me y me compadre: all pairs. Most coders have had times when one return value is just not enough. Some sugary languages allow you to create and return arrays on the fly; others are not so helpful, forcing developers to allocate structs or return arrays of pointers.

In C++, it's easy enough to use the template std::pair and necessary for many STL templates. Maciek's company uses Java, but they wanted in on the fun and decided to write their own class.

See if you can tell me: which one of these things doesn't belong?

  public class Pair
  {
      private Object first;
      private Object second;
      private Object third;

      public Pair() { }
      public Pair( Object first, Object second, Object third )
      {
          this.first  = first;
          this.second  = second;
          this.third  = third;
      }

      public Object getFirst()  { return first; }
      public Object getSecond() { return second; }
      public Object getThird()  { return third; }

      public void setFirst( Object first  )  { this.first  = first; }
      public void setSecond( Object second ) { this.second  = second; }
      public void setThird( Object third  )  { this.third  = third; }
  }

On the plus side, he can claim that his pair is 50% bigger than mine.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!