Absence of property syntax in Java

Posted by Vojislav Stojkovic on Stack Overflow See other posts from Stack Overflow or by Vojislav Stojkovic
Published on 2009-02-03T20:14:46Z Indexed on 2012/06/27 15:16 UTC
Read the original article Hit count: 184

Filed under:
|
|
|

C# has syntax for declaring and using properties. For example, one can declare a simple property, like this:

public int Size { get; set; }

One can also put a bit of logic into the property, like this:

public string SizeHex
{
    get
    {
        return String.Format("{0:X}", Size);
    }
    set
    {
        Size = int.Parse(value, NumberStyles.HexNumber);
    }
}

Regardless of whether it has logic or not, a property is used in the same way as a field:

int fileSize = myFile.Size;

I'm no stranger to either Java or C# -- I've used both quite a lot and I've always missed having property syntax in Java. I've read in this question that "it's highly unlikely that property support will be added in Java 7 or perhaps ever", but frankly I find it too much work to dig around in discussions, forums, blogs, comments and JSRs to find out why.

So my question is: can anyone sum up why Java isn't likely to get property syntax?

  • Is it because it's not deemed important enough when compared to other possible improvements?
  • Are there technical (e.g. JVM-related) limitations?
  • Is it a matter of politics? (e.g. "I've been coding in Java for 50 years now and I say we don't need no steenkin' properties!")
  • Is it a case of bikeshedding?

© Stack Overflow or respective owner

Related posts about java

Related posts about syntax