java - Why do I get a warning when I cast X to X? -


I have a class that implements the interface that declares a method with return type

  X & lt; Item & gt;   

And I'm calling another class with a method m () which

  X   

I try to return the result directly by casting it:

  back (x and lieutenant; items & gt;) others. M ()   

Why do I get a warning? What could possibly go wrong? Is there any way to do this which avoids warning?

Because it can be a X & lt; SubItem & gt; , which can be found in the X < Items & gt; is not.

What you are doing is naturally insecure; X

If you are sure that this is actually a X < Items & gt; , you can use unsafe artists, and you can manually press the warning, because you know more than the compiler.

If you are not entirely sure, then your code is broken, and you need to reconsider your type.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -