Class Tuple2<T1,​T2>


  • public final class Tuple2<T1,​T2>
    extends java.lang.Object
    A representation of a pair of values, typically of different types.

    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 Summary

      Fields 
      Modifier and Type Field Description
      T1 first  
      T2 second  
    • Constructor Summary

      Constructors 
      Constructor Description
      Tuple2​(T1 first, T2 second)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)
      equals(Object) will always throw UnsupportedOperationException.
      int hashCode()
      hashCode() will always throw UnsupportedOperationException.
      java.lang.String toString()
      Human readable string representation which invokes the contained instances' toString() implementation.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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 java.lang.Object
        Throws:
        java.lang.UnsupportedOperationException - will always throw this when invoked
      • equals

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

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