Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unnecessary cast warning...I can't figure out why

843793Nov 5 2004 — edited Nov 8 2004
I've got my compiler warning me of unnecessary casts, and this method generates one of the warnings:
    public static<T> T doIt(T input) {
        Object result = null;
        return (T) result; // Warning: Unnecessary cast to type T for expression of type Object
    }
Can anybody explain why it doesn't like me casting to type T? I get a compiler error if I don't make the cast.

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 6 2004
Added on Nov 5 2004
9 comments
496 views