Who extends interfaces? And why?

Posted by Gangnus on Programmers See other posts from Programmers or by Gangnus
Published on 2012-02-29T08:54:17Z Indexed on 2013/07/01 16:29 UTC
Read the original article Hit count: 180

Filed under:
|
|

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?

© Programmers or respective owner

Related posts about java

Related posts about interfaces