2015-09-07 11:44:36 -06:00
|
|
|
// generics/TupleTest.java
|
2016-12-30 17:23:13 -08:00
|
|
|
// (c)2017 MindView LLC: see Copyright.txt
|
2015-11-15 15:51:35 -08:00
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
2016-09-23 13:23:35 -06:00
|
|
|
// Visit http://OnJava8.com for more book information.
|
2015-11-11 20:20:04 -08:00
|
|
|
import onjava.*;
|
2015-06-15 17:47:35 -07:00
|
|
|
|
|
|
|
public class TupleTest {
|
2015-11-11 20:20:04 -08:00
|
|
|
static Tuple2<String, Integer> f() {
|
2015-06-15 17:47:35 -07:00
|
|
|
// Autoboxing converts the int to Integer:
|
2015-11-11 20:20:04 -08:00
|
|
|
return new Tuple2<>("hi", 47);
|
2015-06-15 17:47:35 -07:00
|
|
|
}
|
2015-11-11 20:20:04 -08:00
|
|
|
static Tuple3<Amphibian, String, Integer> g() {
|
|
|
|
return new Tuple3<>(new Amphibian(), "hi", 47);
|
2015-06-15 17:47:35 -07:00
|
|
|
}
|
|
|
|
static
|
2015-11-11 20:20:04 -08:00
|
|
|
Tuple4<Vehicle, Amphibian, String, Integer> h() {
|
2015-06-15 17:47:35 -07:00
|
|
|
return
|
2015-11-11 20:20:04 -08:00
|
|
|
new Tuple4<>(
|
2015-06-15 17:47:35 -07:00
|
|
|
new Vehicle(), new Amphibian(), "hi", 47);
|
|
|
|
}
|
|
|
|
static
|
2016-01-25 18:05:55 -08:00
|
|
|
Tuple5<Vehicle, Amphibian, String, Integer, Double> k() {
|
2015-06-15 17:47:35 -07:00
|
|
|
return new
|
2015-11-11 20:20:04 -08:00
|
|
|
Tuple5<>(
|
2015-06-15 17:47:35 -07:00
|
|
|
new Vehicle(), new Amphibian(), "hi", 47, 11.1);
|
|
|
|
}
|
|
|
|
public static void main(String[] args) {
|
2015-11-11 20:20:04 -08:00
|
|
|
Tuple2<String, Integer> ttsi = f();
|
2015-06-15 17:47:35 -07:00
|
|
|
System.out.println(ttsi);
|
2016-11-21 12:37:57 -08:00
|
|
|
// ttsi.a1 = "there"; // Compile error: final
|
2015-06-15 17:47:35 -07:00
|
|
|
System.out.println(g());
|
|
|
|
System.out.println(h());
|
|
|
|
System.out.println(k());
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
}
|
|
|
|
/* Output:
|
2015-06-15 17:47:35 -07:00
|
|
|
(hi, 47)
|
2016-07-22 14:45:35 -06:00
|
|
|
(Amphibian@1c7c054, hi, 47)
|
|
|
|
(Vehicle@14991ad, Amphibian@d93b30, hi, 47)
|
|
|
|
(Vehicle@a14482, Amphibian@140e19d, hi, 47, 11.1)
|
2015-09-07 11:44:36 -06:00
|
|
|
*/
|