Well no. See that on the left you are using the generic type ArrayList, where on the right you are using the raw type ArrayList () ;, you can add whatwhat.add ("new :)", and Java will automatically warp the "new" to a new line. This is called autoboxing. While casting is not needed to extract the value from the list with the specified element type, since the compiler already knows the element type. The reason you get an error when you are not eligible is because it should
ArrayList<String> whatwhat = new ArrayList<>(); ...
ArrayList<String> whatwhat = new ArrayList<String>(); ...
source
share