Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4421126

"Semi" type for variables between private and public.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0
    • specification
    • generic
    • generic



      Name: ssT124754 Date: 03/02/2001


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

      Hi,

      I was wondering why there isn't a sort of "hybrid" type of variables in Java.
      Something that would be private for writing, but public for reading. It would
      really make programming easier, and give a whole new dimension to OO
      programming style.

      For every private variable I have got, I must create a public method to write and read the variable, eg:

      public class Lives
      {
          private int lives;

          public void setLives(int i)
          {
              lives=i;
          }

          public int getLives()
          {
              return lives;
          }
      }

      and somewhere else:

      Lives l=new Lives();
      display=l.getLives();

      **************

      Now just imagine there was a type called hybrid. It would allow me to ensure that I don't mistakenly write to the lives variables (and I can easily search for the method setLives in all my files if I need to trace a bug), but I wouldn't need the getLives method to get the value of lives...

      It would be something like this:

      public class Lives
      {
          hybrid int lives;

          public void setLives(int i)
          {
              lives=i;
          }
      }

      and somewhere else:

      Lives l=new Lives();
      display=l.lives;

      Do you get my point ?

      Alok Menghrajani
      ###@###.###
      (Review ID: 117928)
      ======================================================================

            abuckley Alex Buckley
            ssultanasunw Shaheen Sultana (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: