[1881] in java-interest
re: extending String functionality
daemon@ATHENA.MIT.EDU (Christophe Meessen)
Tue Sep 19 08:39:29 1995
Date: Tue, 19 Sep 1995 12:02:37 +0200
To: Glen.Perkins@mediacity.com (Glen C. Perkins), java-interest@java.sun.com
From: meessen@cppm.in2p3.fr (Christophe Meessen)
At 17:48 18/09/95 -0700, Glen C. Perkins wrote:
>I must have been asleep, but I didn't realize until this thread started
>that most of the fundamental classes (String, Integer, Float, etc.) are
>"final" classes meaning they can't have subclasses.
>
...
>Another poster was mentioning having to create wrappers for all of the
>methods in String in order to include them in this homemade base I'm
>calling "SuperString". If I were to do it, I'd just call the methods of the
>String variable encapsulated within the subclass. For example, I create the
>class "SuperString" and it has one variable in its definition:
>
>class Superstring () {
>String theActualString;
>...}
This method breaks down with the operators. Suppose I need my own Integer class.
This class would have the smell, color ad taste of an integer but would have
extended functionalities. Well... too bad, it is not possible.
Wrapping the integer class ? hopeless because operators can't be overloaded.
So I had to define a class with a "int get_value()" and a "void
set_value(int)" method. If we can't overload operators, and I agree with
this rule because the price is too high for the liberty, we must at least be
allowed to extend base types.
Consider the simple example :
actual :
a.set_value( a.get_value() + 1 );
What I wished to be allowed to write :
a = a + 1;
or
a += 1;
This is the price I have to pay. Where is the benefit in defining the integer
class final ?
As stated, the same goes for arrays or Strings.
Bien cordialement,
Ch.Meessen
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com