-2

I wont try to extends a Pattern because we can't (I will wrap), but I would like to know why Pattern class is final ?

I mean this class could be extended for a largest use but they did the choice to make it final. Why ?

If i ask it, it is more in a technical (curious ?) way than in a "java is so bad" way.

troc
  • 379
  • 2
  • 4
  • 16
  • 1
    I don't understand your question. Please clarify and elaborate a bit. Not my down-vote by the way. I will await your response before down-voting. – Hovercraft Full Of Eels Dec 01 '12 at 21:34
  • 2
    @HovercraftFullOfEels Seems like the OP just wants to know the reasoning behind why the `Pattern` is declared `final` in Java. Seems reasonable enough to me... – Tim Pote Dec 01 '12 at 21:36
  • 3
    @TimPote: I understand that, but I want to understand the impetus behind the question. Why is he trying to extend it in the first place? It smells kludgy to me, and likely there's a better way. Anyone can state what has been stated in the answer by Matt, but that doesn't get us to why he's trying to do this in the first place. There's a deeper question that he's not asking. – Hovercraft Full Of Eels Dec 01 '12 at 21:37
  • 3
    @HovercraftFullOfEels Agreed, sounds like an [XY Problem](http://mywiki.wooledge.org/XyProblem) overall. – Tim Pote Dec 01 '12 at 21:42
  • @TimPote: a wonderful paradigm, thanks! I will definitely borrow this idea. – Hovercraft Full Of Eels Dec 01 '12 at 21:44

1 Answers1

6

It's final specifically to prevent you from extending it, because it is not designed to be subclassed. Pattern instances are immutable and thread-safe, neither of which would be guaranteed if you created your own subclass of Pattern.

Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • Ok I see thanks to your links. By extending we could overwrite an optimised method and break java performances – troc Dec 01 '12 at 21:44
  • 2
    @souf what? No, it's not just a question of performance. You could break _correctness!_ – Matt Ball Dec 01 '12 at 21:46