java - Create generic Interface restricted to own class -


i create generic interface 2 classes i'm not sure how specify generics right way.

public class thinga implements thing {     public thinga createcopy(thinga original); }  public class thingb implements thing {     public thingb createcopy(thingb original); } 

i tried this.

public interface thing<v extends thing<v>> {     public v createcopy(v original);  } 

but i'm still able things this, shouldn't allowed.

public class thingb implements thing<thinga> {     public thinga createcopy(thinga original); } 

there no this key-word generics (nor methods parameters , return values declaration) , cannot want.

in other words interface permit ensure methods in class use consistent types, not reference class type itself.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -