[1821] in java-interest

home help back first fref pref prev next nref lref last post

Re: const (was: A few queries...)

daemon@ATHENA.MIT.EDU (John Barton)
Mon Sep 18 13:18:25 1995

To: Doug Lea <dl@altair.cs.oswego.edu>
Cc: mlorton@eshop.com, mason_l@ee.uwa.edu.au, java-interest@java.sun.com
In-Reply-To: Your message of Sun, 17 Sep 1995 08:13:47 EDT.
             <199509171213.IAA05588@gee.cs.oswego.edu>
Date: Mon, 18 Sep 1995 09:39:00 -0400
From: John Barton <jjb@watson.ibm.com>




>> >
>> > 1)   Pass-by-value vs pass-by-reference vs pass-by-const-reference
>> >
>> Yeah, constancy was a curious omission from the language.
>
>As Mark Linton once pointed out, this sense of C++ `const' is
>basically syntactic support for a certain coding convention that can
>also be had by partitioning methods into different classes.  To get
>the effect of C++ const methods, as in:
>
>  class A {
>  public:
>    void m1() const { ... }
>    void m2() { ... }
>  }
>
>you could write in Java
>
>  class A {
>    public void m1() { ... }
>  }
>
>  class MutableA extends A {
>    public void m2() { ... }
>  };
>
>A client operation, say
>  void use(A a)
>can normally only access m1, even if `a' is actually of a subclass
>supporting other methods (like m2).


  "const" is another one of the C++ features that works fine in limited
circumstances.  If you use lots of indirection "const", is not very useful
since pointer members of const objects can be used to write on pointed-to
objects:
   struct X {     // C++
      X *p;
      void writeOnIt() { p=0; }
      void foo() const { p->writeOnIt(); }  // No compile error.
   };
Since everything in java is indirect, its semantics are already like those
of C++ (yea, I know, not considered by all to a feature).

  Another perpetual problem with "const" is collections: to write const
safe collections you have to use the two-class approach Doug outlined above
even in C++ with its const support.

  Given that const is mostly valuable as an argument modifier, eg const Foo&
means "in" parameter,  does java have a story for dealing with specifying
RPC arguments?  The "in", "out", "inout" modifiers in many RPC languages
seems pretty important yes?  Is there an equivalent already?

John.







-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post