Skip to content

Commit 324ed63

Browse files
committed
Java 11 Changes
1 parent 54cea15 commit 324ed63

4 files changed

Lines changed: 58 additions & 3 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
<artifactId>maven-compiler-plugin</artifactId>
2424
<version>3.7.0</version>
2525
<configuration>
26-
<source>1.8</source>
27-
<target>1.8</target>
26+
<source>11</source>
27+
<target>11</target>
2828
</configuration>
2929
</plugin>
3030
</plugins>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.ab.generics.basic;
2+
3+
4+
//Allowed
5+
public class NamingGeneric<C> {
6+
7+
public <M> M test(M t){
8+
return null;
9+
}
10+
11+
public <N> N test3(N t){
12+
return null;
13+
}
14+
public <M> M test4(C t){
15+
return null;
16+
}
17+
public <M> C test5(M t){
18+
return null;
19+
}
20+
//here C hides the C Type at class level
21+
public <C> C test2(C t){
22+
return null;
23+
}
24+
}
25+
//public class NamingGeneric<Object> {}
26+
//public class NamingGeneric<String>{}
27+
//public class NamingGeneric<NamingGeneric> {}
28+
29+
//not allowed
30+
//public class NamingGeneric<?> {}
31+

src/main/java/com/ab/generics/methods/ListMinimum.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.ab.generics.model.Person;
55

66
import java.util.ArrayList;
7+
import java.util.Collection;
78
import java.util.Comparator;
89
import java.util.List;
910

@@ -48,4 +49,8 @@ private static Object min(List values, Comparator comparator) {
4849
}
4950
return lowestElement;
5051
}
52+
53+
public static void test(Collection<?> collection){
54+
55+
}
5156
}

src/main/java/com/ab/generics/wildcard/Unbounded.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.ab.generics.model.Person;
44

55
import java.util.ArrayList;
6+
import java.util.HashSet;
67
import java.util.List;
78

89
/**
@@ -11,6 +12,15 @@
1112
public class Unbounded {
1213

1314
public static void main(String[] args) {
15+
//List objects = new ArrayList();
16+
//List objects = new ArrayList( );
17+
//List objects = new ArrayList<>();
18+
//List objects = new ArrayList< >( );
19+
//List objects = new ArrayList< Object >( );
20+
21+
//List<> objects = new ArrayList();//not allowed
22+
23+
//List<Object> objects = new ArrayList();
1424
List<Object> objects = new ArrayList<>();
1525
objects.add(1);
1626
objects.add("abc");
@@ -24,7 +34,7 @@ public static void main(String[] args) {
2434
objects2.add(null);
2535
//Compile time error
2636
//objects2.add(1);
27-
//objects2.add("abc")
37+
//objects2.add("abc");
2838
//objects2.add(new Object());
2939
//objects2.add(new Person("Nish", 28));
3040
System.out.println(objects2);
@@ -35,6 +45,15 @@ public static void main(String[] args) {
3545
objects3.add(new Person("Nish", 28));
3646
System.out.println(objects3);
3747

48+
//var objects4 = new HashSet<?>();//not allowed
49+
//var objects4 = new HashSet<String>();//allowed
50+
var objects4 = new HashSet<>();//implicit object type inferred
51+
objects4.add(1);
52+
objects4.add("abc");
53+
objects4.add(new Object());
54+
objects4.add(new Person("Nish", 28));
55+
System.out.println(objects4);
56+
3857

3958
}
4059
}

0 commit comments

Comments
 (0)