File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
CodingBlocks Training/Day23/generics Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ package Lecture23 .generics ;
2+
3+ public class client {
4+
5+ public static void main (String [] args ) {
6+
7+ genericPair <Integer > pair1 = new genericPair <Integer >();
8+
9+ pair1 .one = 1 ;
10+ pair1 .two = 2 ;
11+
12+ // pair1.one = "hello"; // Type mismatch: cannot convert from String to Integer
13+
14+
15+ Integer one = pair1 .one ;
16+ System .out .println (one ); // 1
17+
18+ GenericPair2D <Integer , String > pair2 = new GenericPair2D <Integer , String >();
19+
20+ pair2 .one = 1 ;
21+ pair2 .two = "two, yay! I can hold string" ;
22+
23+ String two = pair2 .two ;
24+ System .out .println (two );
25+
26+ GenericPair2D <String , Integer > pair3 = new GenericPair2D <String , Integer >();
27+
28+ pair3 .one = "one, yay! I can also come first " ;
29+ pair3 .two = 2 ;
30+
31+ System .out .println (pair3 .one );
32+ }
33+
34+ }
You canβt perform that action at this time.
0 commit comments