-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathArrayIsIterable.java
More file actions
40 lines (32 loc) · 933 Bytes
/
ArrayIsIterable.java
File metadata and controls
40 lines (32 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package holding;
/**
* RUN:
* javac holding/ArrayIsIterable.java && java holding.ArrayIsIterable
* OUTPUT:
* 1 2 3 A B C
*/
import java.util.*;
public class ArrayIsIterable {
static <T> void test(Iterable<T> ib) {
for(T t : ib) {
System.out.print(t + " ");
}
}
public static void main(String[] args)
{
// Ok !!!
test(Arrays.asList(1, 2, 3));
String[] strings = {"A", "B", "C"};
// Error !!!
//
// required: Iterable<T>
// found: String[]
// reason: no instance(s) of type variable(s) T exist so that argument type String[] conforms to formal parameter type Iterable<T>
// where T is a type-variable:
// T extends Object declared in method <T>test(Iterable<T>)
//
//test(strings);
// Ok !!!
test(Arrays.asList(strings));
}
}