AFAIK, my class extends parent classes and implements interfaces. But I run across a situation, where I can't use implements SomeInterface. It is the declaration of a generic types. For example:
public interface CallsForGrow {...}
public class GrowingArrayList <T implements CallsForGrow> // BAD, won't work!
extends ArrayList<T>
Here using implements is syntactically forbidden. I thought first, that using interface inside <> is forbidden at all, but no. It is possible, I only have to use extends instead of implements. As a result, I am "extending" an interface. This another example works:
public interface CallsForGrow {...}
public class GrowingArrayList <T extends CallsForGrow> // this works!
extends ArrayList<T>
To me it seems as a syntactical inconsistancy. But maybe I don't understand some finesses of Java 6? Are there other places where I should extend interfaces? Should the interface, that I mean to extend, have some special features?
extendsandimplements, it's just when looking at the issue from a pure type-system perspective, that there is no difference. – Joachim Sauer Feb 29 '12 at 09:05Tis a class?Tcould reference an interface type or anenumtype. – Joachim Sauer Feb 29 '12 at 10:03implements it and in general that's not necessary whenextending a class. There are exceptions for both "rules". – Joachim Sauer Feb 29 '12 at 15:43<A, B extends A>. In that case, you don't even know ifAis a class, an interface, an enum or an annotation (you don't know that aboutBeither, by the way). Again: the information about the specific kind of type is not interesting in this context. – Joachim Sauer Feb 29 '12 at 15:45extends, it does not make sense for me to see aninterfaceto extend anotherinterface. Take for examplepublic interface List extends Collection{}Do you mean,Listis-aIterable, BecauseListis-aCollectionandCollectionis-aIterable? i think this is wrong as per this answer.If one is getting into a scenario of aninterfaceextendsanotherinterface, then it means that already existing design approach was wrong or the current design approach is wrong. – overexchange Dec 12 '14 at 02:46extendswhen (potentially) referring to interfaces. Your comment seems to be about the unrelated topic of "should I use interfaces or classes". If you've got a specific question about that, please post that separately. – Joachim Sauer Dec 12 '14 at 11:40<T extends CallsForGrow>mean<SubType vis-a-vis SuperType>,interfaceis one type in this case. 2) we already know the scenario ofclass xyz implements abc{}. 3)interface abc extends def, xyz {}This is just gathering of methods and nothing more than that. In my previous comment, am trying to say that we get into the scenario as per third point mentioned here, due to design flaw. – overexchange Dec 12 '14 at 13:00:. and under the covers, an interface is and has always been an abstract class with the constraint of only containing unimplemented virtual (abstract) members, so as to allow for multiple inheritence. there is literally no difference betweenimplementsandextends. they could both be replaced with the same word (extends) or by some arbitrary symbol (:) and nothing would be lost. – sara May 20 '16 at 18:15