Bad idea, generally, to extend Sun classes. Better to create your own class that takes either: a String, a long or BigInteger in its constructor. Have the actual BigInteger be an instance variable in your custom class that is initialized in the constructor. Finally, add public methods and delegate the calls you need to the nested BigInteger.
- Saish
Bruce Eckel, author of [url=http://www.mindview.net/Books/TIJ/]Thinking In Java[/url], has this to say about composition vs. inheritance:
When deciding between inheritance and composition, ask if you need to upcast to the base type. If not, prefer composition (member objects) to inheritance. This can eliminate the perceived need for multiple base types. If you inherit, users will think they are supposed to upcast.
Choose composition first when creating new classes from existing classes. You should only used inheritance if it is required by your design. If you use inheritance where composition will work, your designs will become needlessly complicated.
Bill Venners: [url=http://www.artima.com/designtechniques/compoinh.html]Composition versus Inheritance[/url]
Use inheritance (of implementation) only when the class satisfies the following criteria:
1) "Is a special kind of," not "is a role played by a";
2) Never needs to transmute to be an object in some other class;
3) Extends rather than overrides or nullifies superclass;
4) Does not subclass what is merely a utility class (useful functionality you'd like to reuse); and
5) Within PD: expresses special kinds of roles, transactions, or things.
-- from [url=http://www.amazon.com/exec/obidos/tg/detail/-/0139111816/qid=1094662332/sr=1-5/ref=sr_1_5/002-7366647-8594415?v=glance&s=books]Java Design: Building Better Apps and Applets (2nd Edition)[/url], by Peter Coad and Mark Mayfield
> What behavior are you adding to
> BigInteger that is not already there?
BigInteger probableSafePrime(int bitLength, int certainty, Random rnd)
BigInteger generateQuadraticResidue(BigInteger n, SecureRandom rnd)
BigInteger generateQuadraticResidueGenerator(BigInteger n, BigInteger order, BigInteger[] primeFactor, SecureRandom rnd)
/** badly named.... Return a BigInteger[] representing the n high order bits of x and the n low order bits of x.*/
BigInteger[] split(BigInteger x, int n)
At the moment I have defined these methods as static in a class called MathUtil.