JDK-4421126 : "Semi" type for variables between private and public.
  • Type: Bug
  • Component: specification
  • Sub-Component: language
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2001-03-02
  • Updated: 2007-07-13
  • Resolved: 2007-07-13
Related Reports
Duplicate :  
Description

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) 
======================================================================

Comments
EVALUATION This is really a request for properties; 4228585 is where the votes and discussion have headed on bugs.sun.com.
13-07-2007

EVALUATION In some form or another, such a feature has been suggested many times (long before Java even existed). Essentially, we are talking about a sugar that would automatically define a field and accessor methods, and give suitable control over the accessibility of these members. In some variants, people want to invoke the accessor methods using a field syntax. Some form of this would be harmless and even handy, even though it's just sugar and provides almost no expressive advantage. gilad.bracha@eng 2001-03-02
02-03-2001