Sometimes Java generics simply do not allow you to do what you want, and you need to effectively tell the compiler that what you do will be legal at runtime.
So, SuppressWarning annotation is used to suppress compiler warnings for the annotated element. Specifically, the unchecked category allows suppression of compiler warnings generated as a result of unchecked type casts. SuppressWarning annotation is used to suppress compiler warnings for the annotated element. Specifically, the unchecked category allows suppression of compiler warnings generated as a result of unchecked type casts. Check this..
@SuppressWarnings("unchecked") A<Integer>[] arr = new A[3]; B(){ for(int i=0;i<arr.length;i++) arr[i]=new A<Integer>(); }
source share