question about interfaces and generics in Java: type mismatch error -
Let's say I have the following interface:
Public Interface interface < T increases the number & gt; {Html}
public vector & lt; Interface & lt; T & gt; & Gt; GetVector (); } and the following classes implementing that interface:
Public abstract class C < T's extension number & gt; Applicable interface & lt; T & gt; {Private vector & lt; C & lt; T & gt; & Gt; Vector; Public vector & lt; Interface & lt; T & gt; & Gt; GetVector () {// Error returned this.vector; Legally a vector & lt; C & lt; T & gt; & Gt; Why is not legal to return (clearly) a vector & lt; Interface & lt; Returning T & gt; & Gt; . C is actually implementing the interface , so it should be possible, right? What am I missing? EDIT:
Why does this work for non-generic interface? Is this really a common problem?
Public Interface Interface {public interface getVector (); } Public abstract class C applied interface {Private C; Public interface getVector () {// errror return this.c; }}
Because vector is clearly created < Code> Interface & lt; T & gt; , Interface & lt; T & gt; Not the things to expand, I believe that if you defined the definition of public vector & lt; Extends the interface & lt; T & gt; & Gt; GetVector (); The problem is that for some V, T or V extends T that foo < V> Foo & lt; T & gt; does not have an overflow. The compiler does not test legacy on general arguments unless you explicitly point to that extension point. vector & lt;? Using the Interface & lt; T & gt; , while vector & lt; Interface & lt; T & gt; & Gt; This means that the interface to apply or extend any class is & lt; T & gt; means "vector with only interface items. It is probably more convincing to consider that the Update : I tested this and have been compiled without the following errors or warnings
Interface interface gt; public vector & lt;? Extension of the interface & lt; T & gt; getVector () Gt; get.wector () come here this return.vector;}} table C / code>
Comments
Post a Comment