Add Syntax Similar to Pascal's "with" Statement

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Won't Fix
    • Priority: P4
    • None
    • Affects Version/s: 1.3.0
    • Component/s: specification
    • generic
    • generic



      Name: boT120536 Date: 06/03/2001


      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

      Pascal has a helpful statement: the "with" statement. It not only saves some
      typing, but also, IMHO, makes things look a bit neater as well (and reduces
      redundancy).

      Let's say we have a class called "Bicycle" with an instance named "myBike".

      Example in Pascal:

           with myBike do
                axleLength = 12;
                wheelCount = 2;
                playingCardsOnWheels = true;
           end

      is equivalent to:

           myBike.axleLength = 12;
           myBike.wheelCount = 2;
           myBike.playingCardsOnWheels = true;

      I would love to see a similar construct in Java. Here is a proposed example:

           with(myBike) {
                setAxleLength(12);
                setWheelCount(2);
                setPlayingCardsOnWheels(true);
           }

      Basically, for the duration of the "with" block, "this" would point to "myBike"
      and not the class one was actually in. This does bring up the interesting
      thought: how would one access the previous "this"? Any thoughts?

      Thanks!
      (Review ID: 125328)
      ======================================================================

            Assignee:
            Unassigned
            Reporter:
            Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: