-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay21-Generics
More file actions
26 lines (19 loc) · 916 Bytes
/
Day21-Generics
File metadata and controls
26 lines (19 loc) · 916 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
Problem:
Objective
Today we're discussing Generics; be aware that not all languages support this construct, so fewer languages are enabled for this challenge.
Check out the Tutorial tab for learning materials and an instructional video!
Task
Write a single generic function named printArray; this function must take an array of generic elements as a parameter
(the exception to this is C++, which takes a vector). The locked Solution class in your editor tests your function.
Note: You must use generics to solve this challenge. Do not write overloaded functions.
/**
* Method Name: printArray
* Print each element of the generic array on a new line. Do not return anything.
* @param A generic array
**/
// Write your code here
public void printArray(T [] array) {
for (int i=0; i<array.length; i++) {
System.out.println(array[i]);
}
}