extending a final class ? is it possible ?

Discussions

General J2EE: extending a final class ? is it possible ?

  1. extending a final class ? is it possible ? (8 messages)

    Hello,

      I was wondering if it is at all possible to extend a final class? I'd LOVE to extend the String class to include a small function I wrote.

    Thanks in advance,

    Eric
  2. is it a joke?
  3. Sorry but no, this is NO joke.... I know that you can't do this normally, but I was wondering if there was a "work around"...

    Sorry if this is a TOTALLY stupid question, but they let me out of the funny farm today....
  4. if u really want to add a functionality by extending a string class you can do it by modifying String class src from JDK and save it as your own class and use it.thats the only way ...you really cant extend a final class..
  5. You could always 'wrap' a String with a new class, and implement all the constructors & methods.... If you really want to :-)

    Cheers,
    Rick
  6. Thanks guys.... I thought that I might have to do something like get the original String class and modify it, I was just hoping that were was another way....

    thanks again....

    Time for me to return me to the funny farm! "I wouldn't be crazy if everyone would just see it my way!!!".
  7. U can do it in samlltalk.

    Try the free version at www.squeak.org, There are other flavours like IBM's visualage , Dolphin from object arts etc.
  8. Smalltalk that is..
  9. Extending a final class[ Go to top ]

    Yes, surely it can be done, but it is a workaround. The technique to use is Composition. I agree that a final class cannot be extended (inheritance) but it can be used as a back end class which is exposed by a front end class.