Unchecked cast warning only on generic type

Viewed 457

Code sample #1:

public class Foo implements Cacheable {
}

public class Fooer {
    void doSomething(Cacheable obj) {
        Foo foo = (Foo) obj; //#1
    }
}

Code sample #2:

public class GenericFooer<FooClass extends Cacheable> {
    void doSomething(Cacheable obj) {
        FooClass foo = (FooClass) obj; //#2
    }
}

Why do I get an "Unchecked cast: 'Cacheable' to 'FooClass'" warning in case of #2 but NOT in case of #1? This two cases seem exactly the same for me. Am I missing something, or is the code inspector slightly broken?

PS: I'm using InteliJ IDEA Community Edition.

PSS: I know how to get around this warning, the only question is why is it here, if it's not there.

1 Answers
Related