Modernize old code
List
is a raw type, while List<String>
is a parameterized type.
When generics were introduced in JDK 1.5, raw types were retained only to maintain backwards compatibility with older versions of Java. Although using raw types is still possible, they should be avoided:
Example
import java.util.*; public final class AvoidRawTypes { void withRawType(){ //Raw List doesn't self-document, //doesn't state explicitly what it can contain List stars = Arrays.asList("Arcturus", "Vega", "Altair"); Iterator iter = stars.iterator(); while(iter.hasNext()) { String star = (String) iter.next(); //cast needed log(star); } } void withParameterizedType(){ List<String> stars = Arrays.asList("Spica", "Regulus", "Antares"); for(String star : stars){ log(star); } } private void log(Object message) { System.out.println(Objects.toString(message)); } }