OnJava8-Examples/generics/TupleTest2.java
Bruce Eckel bc0026c3e1 Radically reorganized
Plus many new examples in "streams" chapter.
2015-11-11 20:20:04 -08:00

38 lines
979 B
Java

// generics/TupleTest2.java
import onjava.*;
import static onjava.Tuple.*;
public class TupleTest2 {
static Tuple2<String, Integer> f() {
return tuple("hi", 47);
}
static Tuple2 f2() { return tuple("hi", 47); }
static Tuple3<Amphibian, String, Integer> g() {
return tuple(new Amphibian(), "hi", 47);
}
static
Tuple4<Vehicle, Amphibian, String, Integer> h() {
return tuple(new Vehicle(), new Amphibian(), "hi", 47);
}
static
Tuple5<Vehicle, Amphibian, String, Integer, Double> k(){
return tuple(new Vehicle(), new Amphibian(),
"hi", 47, 11.1);
}
public static void main(String[] args) {
Tuple2<String, Integer> ttsi = f();
System.out.println(ttsi);
System.out.println(f2());
System.out.println(g());
System.out.println(h());
System.out.println(k());
}
}
/* Output:
(hi, 47)
(hi, 47)
(Amphibian@139a55, hi, 47)
(Vehicle@1db9742, Amphibian@106d69c, hi, 47)
(Vehicle@52e922, Amphibian@25154f, hi, 47, 11.1)
*/