immutability - Why is Java's BigDecimal class not declared as final? -


while checking source code of java's bigdecimal class, surprised not declared final class:

class bigdecimal

public class bigdecimal extends number implements comparable<bigdecimal> 

immutable, arbitrary-precision signed decimal numbers.

(from oracle docs)

is there specific reason or did developers forget add keyword? practice not declare immutable classes final?

the same goes biginteger, not string declared final.

quote https://blogs.oracle.com/darcy/entry/compatibly_evolving_bigdecimal:

however, there possible complication here since bigdecimal not final , since has public constructors, can subclassed. (as discussed in effective java, item 13, favor immutability, this design oversight when class written.)

(emphasis mine).

since java has favored backward compatibility, making final out of question: break existing subclasses.

that said, when using date, assume no-one ever subclasses bigdecimal, , bigdecimal should used if immutable.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -