Created
July 26, 2019 03:21
-
-
Save ayago/1cd28f4dd44f25da3904808cd324462c to your computer and use it in GitHub Desktop.
Tuples in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lombok.AllArgsConstructor; | |
import lombok.Getter; | |
import java.math.BigDecimal; | |
import java.util.function.Function; | |
import static java.lang.String.format; | |
class SampleTuples { | |
public static void main(String[] args) { | |
Tuple<String, BigDecimal> yourSalary = new Tuple<>("Lead", new BigDecimal("300000")); | |
Tuple3<String, BigDecimal, Function<String, String>> func = new Tuple3<>( | |
"Lead", new BigDecimal("300000"), s -> format("Libre naman %s", s)); | |
} | |
/** | |
* Compound data | |
* | |
* @param <A> First element type | |
* @param <B> Second element type | |
*/ | |
@AllArgsConstructor | |
@Getter | |
public static class Tuple<A, B> { | |
private final A first; | |
private final B second; | |
} | |
/** | |
* Compound data | |
* | |
* @param <A> First element type | |
* @param <B> Second element type | |
*/ | |
@AllArgsConstructor | |
@Getter | |
public static class Tuple3<A, B, C> { | |
private final A first; | |
private final B second; | |
private final C third; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment