Class Pair<L,R>
- java.lang.Object
-
- javafx.util.Pair<L,R>
-
- Type Parameters:
L
- The left typeR
- The right type The identical class (source identical) is vended as two versions:Pair
and itsgetLeft()
andgetRight()
methods are fine to use forever. (Although, I'd recommend an immutable type instead if you can get/make it, and to give better context than left/right)Pair
and itsgetLeft()
andgetRight()
methods are a band-aid forClassNotFoundException
errors encountered when upgrading to JDK 11 or higher.The
ClassNotFoundException
is tricky.Pair
is part of a JavaFX visual effects framework, and that was part of many JDK distributions for a while. The Pair type in particular attracted a bit of usage, but in ways that are unmodeled in package management. (Hey it makes sense, it was just part of the JDK after all.) Now, it's easy enough to upgrade your own code, but if some other dependency was trying to use this tempting little pair class... failure! There's a similar story for library vendors when trying to raise the version required and the effect on your consumers.Unless you're trying to get Unless you intend to do visual effects, bringing in the whole JavaFX project will be too much size/hassle/etc for many cases. Therefore, we can use this tiny little dependency as a shim until unneeded.
A no-dependency alternative is the "Entry" type of Map classes. For example
java.util.AbstractMap.SimpleEntry<K,V>
orjava.util.AbstractMap.SimpleImmutableEntry<K,V>
- All Implemented Interfaces:
java.io.Serializable
public class Pair<L,R> extends java.lang.Object implements java.io.Serializable
A pair of two values, a left and a right.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
equals(java.lang.Object that)
L
getKey()
Deprecated.L
getLeft()
Get the left value.R
getRight()
Get the right value.L
getValue()
Deprecated.int
hashCode()
static <L,R>
Pair<L,R>of(L left, R right)
Make a Pair of things.java.lang.String
toString()
-
-
-
Method Detail
-
of
public static final <L,R> Pair<L,R> of(L left, R right)
Make a Pair of things.- Type Parameters:
L
- The left typeR
- The right type- Parameters:
left
- The left thingright
- The right thing- Returns:
- a new Pair
-
getLeft
public L getLeft()
Get the left value.- Returns:
- the left value
-
getKey
@Deprecated public L getKey()
Deprecated.Get the left value. An alias for thegetLeft()
method, the "getKey" convention is to support use cases wherePair
was used and may be difficult to untangle.- Returns:
- the left value
-
getRight
public R getRight()
Get the right value.- Returns:
- the right value
-
getValue
@Deprecated public L getValue()
Deprecated.Get the right value. An alias for thegetRight()
method, the "getKey" convention is to support use cases wherePair
was used and may be difficult to untangle.- Returns:
- the right value
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object that)
- Overrides:
equals
in classjava.lang.Object
-
-