Mini article raw type in java (#7142)

* Raw type example implementation
This commit is contained in:
nikunjgandhi1987 2019-06-20 23:19:33 -05:00 committed by Josh Cummings
parent 3e1107f217
commit 01bfd6a353
1 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,25 @@
package com.baeldung.rawtype;
import java.util.ArrayList;
import java.util.List;
public class RawTypeDemo {
public static void main(String[] args) {
RawTypeDemo rawTypeDemo = new RawTypeDemo();
rawTypeDemo.methodA();
}
public void methodA() {
// parameterized type
List<String> listStr = new ArrayList<>();
listStr.add("Hello Folks!");
methodB(listStr);
String s = listStr.get(1); // ClassCastException at run time
}
public void methodB(List rawList) { // Inexpressive raw type
rawList.add(1); // Unsafe operation
}
}