Combining generic type parameters with interfaces in Java -


as many inheritance problems, find hard explain want do. quick (but peculiar) example should trick:

public interface shell{       public double getsize();  }  public class tortoiseshell implements shell{      ...      public double getsize(){...} //implementing interface method      ...      public tortoise gettortoise(){...} //new method      ... }  public class shellviewer<s extends shell>{       s shell;       public shellviewer(s shell){          this.shell = shell;          ...      }  }  public class tortoiseshellviewer<t extends tortoiseshell> extends shellviewer{      public tortoiseshellviewer(t tshell){          super(tshell); //no problems here...     }      private void removetortoise(){         tortoise t = tshell.gettortoise(); //error: compiler can not find method in "shell"         ...     } } 

the compiler not recognise want use specific implementation of shell gettortoise(). have gone wrong?

based on you've given here, problem that:

public class tortoiseshellviewer<t extends tortoiseshell> extends shellviewer 

does not specify shellviewer (which generic) correctly. should be:

public class tortoiseshellviewer<t extends tortoiseshell> extends shellviewer<t> 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -