Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

16. Collections and Generics: Data struc... > In generics, “extends” means “extend...

In generics, “extends” means “extends or implements”

The Java engineers had to give you a way to put a constraint on a parameterized type, so that you can restrict it to, say, only subclasses of Animal. But you also need to constrain a type to allow only classes that implement a particular interface. So here’s a situation where we need one kind of syntax to work for both situations—inheritance and implementation. In other words, that works for both extends and implements.

And the winning word was... extends. But it really means “is-a”, and works regardless of whether the type on the right is an interface or a class.

In generics, the keyword “extends” really means “is-a”, and works for BOTH classes and interfaces.

image with no caption

Q:

Q: Why didn’t they just make a new keyword,“is”?


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial