• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why some java API classes are not final?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,

I was just wondering that we hardly extend some classes like ArrayList or classes from Collection API or IO stream classes, I actually never extended these. Why these classes are not made final? Any specific reason?

Thank you.
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Priti Ksharma wrote:Dear all,

I actually never extended these

Thank you.



Maybe there are others who need to extend it besides you?

Direct Known Subclasses:
AttributeList, RoleList, RoleUnresolvedList
 
Priti Ksharma
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sam, can you give any example where we will need to extend these classes?
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Priti Ksharma wrote:Sam, can you give any example where we will need to extend these classes?



Why does it matter? All that really matters is the designers considered that there might be some use to somebody to be able to extend them, and there was no harm in doing so, so there was no need to make them final.

And Sam gave you examples of 3 classes in the core API that extend ArrayList. What more do you need?
 
Marshal
Posts: 79239
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Library classes are usually designed differently from ordinary classes. In ordinary classes, you try to make the public interface as small as possible, only providing something public if you can think of a good reason for it.
In library classes, you tend to provide things public just in case anybody wants them. You might only make a library classes un-extendable if they are to be immutable.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic