Java Virtal

[ News ] rss

February 01, 2011

Mark Wielaard: New GPG key. Finally created a new GPG key using gnupg. The old one was a DSA/1024 bits one and 8 years old. The new one is a RSA/2048 bits one. I will use the new one in the future to sign any release tarballs I might create. pub 2048R/57816A6A 2011-01-29 Key f...

More »

February 01, 2011

Andrew Hughes: [SECURITY] IcedTea6 1.7.8, 1.8.5, 1.9.5 Released!. We are pleased to announce a new set of security releases, IcedTea6 1.7.8, IcedTea6 1.8.5 and IcedTea6 1.9.5. This update contains the following security updates: The IcedTea project provides a harness to build the source code from OpenJDK6 u...

More »

1718 1920212223

[ Archives News
for 'Developers' ]

home > news > developers > code advice #11: initialize fields using the property name

Code Advice #11: Initialize fields using the property name

(See intro for a background and caveats on these coding advice blog entries.) How do you initialize fields in a constructor? And how do you initialize fields in a JavaBean setter method? Here's the, in my opinion, correct way to do it: void setTemperature(int temperature) { this.temperature = temperature; } The same scheme is used in constructors. There are various other ways to do this. Dave Yost argues that you should use the following pattern: void setTemperature(int newTemperature) { temperature = newTemperature; } Another coding style guide recommends that you "consider using the prefix a or an with parameter names. This helps make the parameter distinguishable from local and instance variables": void setTemperature(int aTemperature) { temperature = aTemperature; } A third scheme I've seen quite frequently is choosing a parameter name that is an abbreviation for the property name being set: void setTemperature(int temp) { temperature = temp; } A fourth suggestion is to use underscores as suffixes on the field names themselves: void setTemperature(int temperature) { temperature_ = temperature; } So, why do I think my way is the right way to do it, and not the other alternatives shown? As always, the first reason is that the this.x...

Date: July, 25 2006

Others News

© mobirise | mobirise builder | icon font | bootstrap modal popup | bootstrap forms