BAEL-1069: Guide to diamond operator in Java
This commit is contained in:
parent
65e2f59681
commit
119c288942
@ -0,0 +1,5 @@
|
|||||||
|
package org.baeldung.java.diamond;
|
||||||
|
|
||||||
|
public class Car<T extends Engine> implements Vehicle<T> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package org.baeldung.java.diamond;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class DiamondOperatorTest {
|
||||||
|
@Test
|
||||||
|
public void shouldCreateCarUsingDiamondWithoutWarnings() {
|
||||||
|
Car<Diesel> myCar = new Car<>();
|
||||||
|
assertNotNull(myCar);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package org.baeldung.java.diamond;
|
||||||
|
|
||||||
|
public class Diesel implements Engine {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() {
|
||||||
|
System.out.println("Started Diesel...");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package org.baeldung.java.diamond;
|
||||||
|
|
||||||
|
public interface Engine {
|
||||||
|
|
||||||
|
void start();
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package org.baeldung.java.diamond;
|
||||||
|
|
||||||
|
public interface Vehicle<T extends Engine> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package org.baeldung.java.rawtypes;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class RawTypesTest {
|
||||||
|
@Test
|
||||||
|
public void shouldCreateListUsingRawTypes() {
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
List myList = new ArrayList();
|
||||||
|
myList.add(new Object());
|
||||||
|
myList.add("2");
|
||||||
|
myList.add(new Integer(1));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user