Recompile with -Xlint:unchecked for detail error in java

We Are Going To Discuss About Recompile with -Xlint:unchecked for detail error in java. So lets Start this Java Article.

Recompile with -Xlint:unchecked for detail error in java

  1. Recompile with -Xlint:unchecked for detail error in java

    When you compile the code use this:
    javac -Xlint:unchecked
    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\

  2. Recompile with -Xlint:unchecked for detail error in java

    When you compile the code use this:
    javac -Xlint:unchecked
    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\

Solution 1

When you compile the code use this:

javac -Xlint:unchecked

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

Original Author Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment