JDK-6180800 : Allow Programmable Fields (C#/VB.NET-style Properties)
  • Type: Enhancement
  • Component: specification
  • Sub-Component: language
  • Affected Version: 5.0
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-10-18
  • Updated: 2010-04-04
  • Resolved: 2006-11-17
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
C# and VB.NET and VB6 provide the ability to define an object field which is, in fact, programmed inside the object.  That is, the object contains a set-method and a get-method, but from outside the object, these methods are not seen and appear as a simple field.

In C# the notation looks like:
public class myClass
{
   private string name;
   public string Name
   {
      get
      {
         return name;
      }
      set
      {
         name = value;
      }
   }
}

But it may be read and written just as obj.Name:

obj.Name = "Hello";
string temp = obj.Name;

In VB.NET and VB6 the notation is even more powerful and permits multiple parameters on the Property:

obj.Name(37) = "Hello"
Private temp As String = obj.Name(42)


JUSTIFICATION :
Code written using programmable fields is simpler to read and write than code using getters and setters.  As more and more classes are generated with getters and setters, rules using those classes become harder to read and write.

And on a personal note, I am getting complaints from customers and have to tell them, "Well, you are the one who asked to have it in Java."

And they are right.
    if (ab.fred > cd.george) ef.jane = gh.sally + ij.mary;
Is definitely easier to understand than:
    if (ab.getfred() > cd.getgeorge()) ef.setjane(gh.getsally() + ij.getmary());



CUSTOMER SUBMITTED WORKAROUND :
Use get and set methods.
###@###.### 10/18/04 21:18 GMT

Comments
EVALUATION 6347784 expresses the idea of properties more concisely. 4228585 is the master RFE for properties.
26-10-2006