Using the Diamond Operator when type is not obvious : Diamond Operator « JDK 7 « Java






Using the Diamond Operator when type is not obvious

import java.util.ArrayList;
import java.util.List;

public class Test {

  public static void main(String[] args) {

    List arrayList = new ArrayList<>();
    //List<String> arrayList = new ArrayList<>();
    arrayList.add("First");
    arrayList.add("Second");

  }
}

 








Related examples in the same category

1.Using the Diamond Operator for Constructor Type Inference
2.Using the @SafeVarargs Annotation
3.Using the Diamond Operator and Suppressing Unchecked Warnings(SuppressWarnings)