OnJava8-Examples/generics/TupleTest2.java

42 lines
1.1 KiB
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// generics/TupleTest2.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.
import onjava.*;
import static onjava.Tuple.*;
2015-06-15 17:47:35 -07:00
public class TupleTest2 {
static Tuple2<String, Integer> f() {
2015-06-15 17:47:35 -07:00
return tuple("hi", 47);
}
static Tuple2 f2() { return tuple("hi", 47); }
static Tuple3<Amphibian, String, Integer> g() {
2015-06-15 17:47:35 -07:00
return tuple(new Amphibian(), "hi", 47);
}
static
Tuple4<Vehicle, Amphibian, String, Integer> h() {
2016-01-25 18:05:55 -08:00
return tuple(
new Vehicle(), new Amphibian(), "hi", 47);
2015-06-15 17:47:35 -07:00
}
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 tuple(new Vehicle(), new Amphibian(),
"hi", 47, 11.1);
}
public static void main(String[] args) {
Tuple2<String, Integer> ttsi = f();
2015-06-15 17:47:35 -07:00
System.out.println(ttsi);
System.out.println(f2());
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)
(hi, 47)
(Amphibian@1540e19d, hi, 47)
(Vehicle@7f31245a, Amphibian@6d6f6e28, hi, 47)
(Vehicle@330bedb4, Amphibian@2503dbd3, hi, 47, 11.1)
2015-09-07 11:44:36 -06:00
*/