Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Java have Automatic Properties?

Tags:

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?

like image 491
lomaxx Avatar asked Nov 08 '09 22:11

lomaxx


People also ask

Do we have properties in Java?

Properties is a subclass of Hashtable. It is used to maintain a list of values in which the key is a string and the value is also a string i.e; it can be used to store and retrieve string type data from the properties file. Properties class can specify other properties list as it's the default.

Where is the properties file in Java?

properties file inside your resource folder of the java project. The extension we use for the properties file is . properties.

What is a properties file in Java?

properties is a file extension for files mainly used in Java-related technologies to store the configurable parameters of an application. They can also be used for storing strings for Internationalization and localization; these are known as Property Resource Bundles.


2 Answers

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.

like image 107
Jon Skeet Avatar answered Sep 17 '22 07:09

Jon Skeet


No, there isn't such a thing in Java.

In Eclipse, however, you can automatically implement getter/setter methods for fields with Source > Generate Getters/Setters.

like image 44
Joey Avatar answered Sep 21 '22 07:09

Joey