public class GenericsTest public interface Write void write public sta

 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
public class GenericsTest {
public interface Write<T> {
void write();
}
public static class Writer<T> implements Write<T> {
private T data;
public Writer(T data) {
this.data = data;
}
@Override
public void write() {
System.out.println(data);
}
}
public static void main(String[] args) {
//creating 2 Writer objects - with Integer and String
Writer<Integer> integerWriter = new Writer<Integer>(5);
integerWriter.write();
Write<String> stringWrite = new Writer<String>("String");
stringWrite.write();
}
}