Class Tuple2<T1,​T2>


  • public final class Tuple2<T1,​T2>
    extends Object
    A pair of values. This class is to avoid littering a class with thin wrapper objects for passing around e.g. the state of an operation and the result value. Using this class may be correct, but it is a symptom that you may want to redesign your code. (Should you pass mutable objects to the method instead? Create a new class and do the work inside that class instead? Etc.)
    Author:
    Steinar Knutsen
    • Field Detail

      • first

        public final T1 first
      • second

        public final T2 second
    • Constructor Detail

      • Tuple2

        public Tuple2​(T1 first,
                      T2 second)
    • Method Detail

      • hashCode

        public int hashCode()
        hashCode() will always throw UnsupportedOperationException. The reason is this class is not meant for being put in Container implementation or similar use where Java generics will lead to a type unsafe maintenance nightmare.
        Overrides:
        hashCode in class Object
        Throws:
        UnsupportedOperationException - will always throw this when invoked
      • equals

        public boolean equals​(Object obj)
        equals(Object) will always throw UnsupportedOperationException. The intention is always using the objects contained in the tuple directly.
        Overrides:
        equals in class Object
        Parameters:
        obj - ignored
        Throws:
        UnsupportedOperationException - will always throw this when invoked
      • toString

        public String toString()
        Human readable string representation which invokes the contained instances' toString() implementation.
        Overrides:
        toString in class Object