Does Java have Automatic Properties?

lomaxx picture lomaxx · Nov 8, 2009 · Viewed 11.5k times · Source

In c# you can setup properties like this:

public int CustomerId {get;set;}

Which sets up an automatic property called CustomerId, but I was wondering if there was anything similar in Java?

Answer

Jon Skeet picture Jon Skeet · Nov 8, 2009

No, Java has nothing similar at the moment. Heck, properties in Java are mostly just conventions of get/set methods, rather than being genuinely understood by the compiler as they are in C#. Tools and libraries recognise the get/set pattern, but the language doesn't know about them. (It's possible that in a future version of Java, there'll be more "formal" support.)

Some Java-like languages such as Groovy do have automatic property generation, however.