Recompile with -Xlint:unchecked for detail error in java

When you compile the code use this:

Then you will see:

MyStack.java:6: warning: [unchecked] unchecked cast
    this.s = (T[])new Object[30];
                  ^
  required: T[]
  found:    Object[]
  where T is a type-variable:
     T extends Object declared in class MyStack\

MyStack.java:11: warning: [unchecked] unchecked cast
            T[] b = (T[])new Object[size*2];
                         ^
  required: T[]
  found:    Object[]
  where T is a type-variable:
    T extends Object declared in class MyStack
2 warnings

So bottom line, the problem is due to the creation of the generic type array. To solve this read this link: https://stackoverflow.com/a/530289/588532

Leave a Comment