Shoukd the 'final' keyword should be used on all input parameters?

In my very limited experience as a java programmer have never seen this done any where. Except in the java.lang.Math class which has a final variable, of type double, called PI. As pi is not a value that should change during the execution of a program, though this is not passed in as a parameter.
However, on a new project, a co-worker is proposing the use of the 'final' keyword on all input parameters as a standard. He has about 5 years experience of maintaining java systems and is putting this suggestion forward as in the past people have overwritten values passed in as parameters causing confusion. Personally I don't see why this is such a major issue if one reads the code of the called programs.
I would be grateful if anyone has seen this done before, or has any views on the advantages or disadvantages of this.
Thanks in advance,
LS

Lord_Sidcup wrote:
In my very limited experience as a java programmer have never seen this done any where. Except in the java.lang.Math class which has a final variable, of type double, called PI. As pi is not a value that should change during the execution of a program, though this is not passed in as a parameter.
I'm sorry, but this point is irrelevant. There are lots of final fields (but not that many final parameters) in Java, BTW. Every field you declare in an interface is automatically final, for example.
However, on a new project, a co-worker is proposing the use of the 'final' keyword on all input parameters as a standard. He has about 5 years experience of maintaining java systems and is putting this suggestion forward as in the past people have overwritten values passed in as parameters causing confusion. Personally I don't see why this is such a major issue if one reads the code of the called programs.
IMHO, it's definately not a major issue. It is simply being restrictive, to be restrictive. The guy may have "five years experience", but he sounds lazy, to me. Besides, the first thing I would do in that case (if final were the default), would be something like this:
public void myMethod (final String a, final int b) {
  String myA = a;
  String myB = b;
}And now, what has he won by making it final? It simply added some up front work for some people, with no real added value. Also, if I had to retroactively change my code, I would change it as follows:
//Original Code
public void myMethod (String myA, int myB) {
  String myA = a;
  String myB = b;
// New code
public void myMethod (final String a, final int b) {
  String myA = a;
  String myB = b;
}That way, you wouldn't even have to worry about changing anything else about your method, as the variables actually used in the rest of the body will remain the same.
I would be grateful if anyone has seen this done before, or has any views on the advantages or disadvantages of this.The only thing declaring the parameter final does, is it prevents you from assigning a new value to the variable. The instance that parameter references (as long as it is not immutable to begin with) can still be manipulated. I.E. except in some very narrow, and specific, cases, no value added, simply a restriction that exists to be restrictive.
>
Thanks in advance,
LSEdit: And man, am I slow and long-winded.

Similar Messages

  • Can I switch back and forth the same sim card between an old iPhone 4 and a new one never used in order to activate the latter? Should I use same Apple Account?

    Can I switch back and forth the same sim card between an old iPhone 4 and a new one never used in order to activate the latter? Should I use same Apple Account? Should I activate it via WiFi or iTunes? I am filtering on the MAC no and I cannot read that number from the new iPhone without having it activated??!!
    All I want do is to have the new phone activated and then tested!
    Ciao // Mufftas

    Yes, you can do that.

  • I am using Windows 7 Home Premium 64-bit OS.  I've never had this problem before... today I opened iTunes and it prompted me to download the newest version.  I use iTunes all the time and have updated it multiple times with no issues.  During the installa

    I am using Windows 7 Home Premium 64-bit OS.I've never had this problem before... today I opened iTunes and it prompted me to download the newest version.  I use iTunes all the time and have updated it multiple times with no issues.  During the installation process it gave me an error message that said: 
    Runtime error! 
    Program C:\Program Files\iTunes.exe
    R0634
    An application has made an attempt to load the C runtime library incorrectly.
    Please contact the application's support team for more information.
    I quit the installation, uninstalled iTunes and rebooted my computer.  I now receive a similar message with a slight difference:
    Runtime error! 
    Program C:\Program Files (x86)...
    R0634
    An application has made an attempt to load the C runtime library incorrectly.
    Please contact the application's support team for more information.
    I did not leave anything out from the error message.  It doesn't point to a specific file, it just ends with "(x86)..."  Every time I boot up my computer, this error message pops up on my desktop.
    How do I repair this issue?  I have found multiple suggested solutions but am unsure which one is the best, and I don't want to try a bunch of different things for fear I may make the problem worse.  I would like to try and fix this myself if possible but I need to know if that is really possible or if I need to take my computer to someone for repairs.  Any suggestions will be greatly appreciated!!

    Hi lustyln,
    I'm having a little trouble understanding all of what you are trying to explain. From what I can tell, it sounds like your PC has a lot of software problems and you want to know what is supposed to be there and what isn't.
    For reference, here are your product specifications:
    http://h10025.www1.hp.com/ewfrf/wc/document?cc=us&dlc=en&docname=c01893242&lc=en&product=4043282
    To get your PC software back to how it was when it was first purchased, run a system recovery:
    http://h10025.www1.hp.com/ewfrf/wc/document?cc=us&dlc=en&docname=c01867418&lc=en&product=4043282
    I hope this helps.
    ...an HP employee just trying to help where I can, but not speaking on behalf of HP.

  • The software update to 7.1 on my iphone 5 is 214 mb, while via itunes it's 1.27 gb. what's the difference, which should i use?

    the software update to ios 7.1 on my iphone 5 is 214 mb (settings>>general>>software update), while the update via itunes it's 1.27 gb. what's the difference, and which should i use?

    My preferred method is to do the Update using iTunes on my Computer.
    You will Prompted to Transfer any Content from the Device.
    See the Using iTunes Section Here...
    How to update your iPhone, iPad, or iPod touch
    Make sure you have the Latest Version of iTunes (v11) Installed on your computer
    iTunes free download from www.itunes.com/download
    Note:
    Always Backup before you update
    How to BackUp  >  http://support.apple.com/kb/ht1766
    What gets Backed Up
    iTunes http://support.apple.com/kb/ht4946
    iCloud http://support.apple.com/kb/PH2584

  • Photosmart 7510 not printing photo ink when it should, but using up all the other ink cartridges​.

    I'm printing photos, mostly black and white, and all my regular cartridges are almost depleted when I thought they were printing from the photo ink cartridge.  I want the photo ink cartridge to be used and it still shows full.  I had to run out and get new cartridges which is becoming expensive.
    I have windows 7 and I use the Windows Photo Viewer to print the photos.
    I need steps in how to set my printer properties so that the photo ink cartridge is used.
    As of now, the way I look at it, it would be less expensive to go to Wal-Mart or a local grocery store and print my photos there.
    Thank you.

    Hi,
    Photo ink is actually black and under normal printing (including printing photos) it can last 3 times longer than other inks.
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • How to package different content so that the same license can be used for all content.

    1)      If packaging all the content at the same time, use the same instance of DRMParameters every time you call MediaEncrypter.encryptContent().  All content packaged using the exact same DRMParameters object will be associated with the same license.
    2)      If packaging content at different times, but want to have all the content associated with the same license, you need to use V2KeyParameters.setContentEncryptionKey().  The first time you package a piece of content, you would use ContentEncryptionKey.generate() to generate a new key/license ID.  To use the same key/license for later content, you need to store the info in ContentEncryptionKey, so you can pass in the same values later for the new content.

    To package content at different times using the same license, you need to implement the following:
    Call ContentEncryptionKey.generate to generate a new key and license ID.
    On your V2KeyParameters, call setContentEncryptionKey and pass in the object generated in step 1.
    Call MediaEncrypter.encryptContent and pass in the V2KeyParameters (via DRMParameters), as usual.
    Store the contents of ContentEncryptionKey, so the same values can be used again later.  The key, license ID, and packaging date should all be stored.
    When you want to package additional content using this license, lookup the stored key, license ID, and packaging date and pass these into the ContentEncryptionKey constructor to create a ContentEncryptionKey instance.
    On your V2KeyParameters, call setContentEncryptionKey and pass in the object generated in step 5.
    Call MediaEncrypter.encryptContent and pass in the V2KeyParameters (via DRMParameters), as usual.
    The media packaged in steps 3 and 7 should now be protected using the same license.

  • What is the connection method should i use to connect database to visual basic?

    i'm confusing about that, what is ADO.Net, Entity Framework, LINQ to Entities and LINQ to SQL
    what i should learn to connect my database in SQL to visual basic?

    Hello Galeluo,
    >>i'm confusing about that, what is ADO.Net, Entity Framework, LINQ to Entities and LINQ to SQL
    There are documents for these concepts:
    ADO.Net:
    https://msdn.microsoft.com/en-us/library/e80y5yhx%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
    Entity Framework:
    https://msdn.microsoft.com/en-us/library/vstudio/bb399567(v=vs.100).aspx
    LINQ to Entities:
    https://msdn.microsoft.com/en-us/library/vstudio/bb386964(v=vs.100).aspx
    LINQ to SQL:
    https://msdn.microsoft.com/en-us/library/bb386976(v=vs.110).aspx
    In above links, we can see that all are approaches which could be used to access database except the LINQ to Entities which is a query approach and is based on Entity Framework.
    >>what i should learn to connect my database in SQL to visual basic?
    If you are starting to use the .NET api to connect a database, I suggest you could use the ADO.NET api which is a underlying api, both Entity Framework and LINQ to SQL are based on this one.
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • SRM RFC users for ERP , what are the profile/roles should be used?

    Hi All,
    I have integrated SRM and ERP systems using config wizard. Multiple rfc accounts were created automatically by the wizard but what i did was i skipped on the profile and role field because i don't know what to put. Now, I am battling on what profiles and roles should i put there since the wizard didn't do the automatic placing of authorizations and roles for me.
    here are the users that have been created automatically by the config wizard.
    ERP System:
    SRM2ERP
    SRM2ERPD
    ERPLOCAL
    SRM System:
    ERP2SRM
    ERP2SRMD
    SRMLOCAL
    Please help on what ABAP Roles and Profiles should i place to it.
    Regards,
    Tony
    Edited by: Tony on Jun 9, 2011 12:34 PM

    Hi ,
    The user should have profile SAP_ALL assigned automatically when you run the CTC script.
    Else please assign manually.
    Regards
    Sam

  • I am running a MAC PRO 10.6.8 and it has firefox 3.6.1.3 and it shows no updatres available? My MAC Book PRo has updated to 6.0.2. can I manually update my MAC PRO to 6.0.2 or is there a reason the MAC PRO should NOT use 6.0.2?

    see question above

    I am in my late 60's so I can't imagine all the changes and questions to what to do but... new Macs do not boot from an OS the pre-dates it.
    The Mac Pro is 7.5 yrs old , I have the August 2006 1,1 right here right now.
    Sounds like we have the same system - Mac Pro 1,1 2.66 dual/dual-core (total of 4-cores) DDR2 FB-DIMMs et c.
    These cannot run Mountain Lion 10.8.x
    The PowerMac G5 came out in Sept/Oct 2003 and shipping with10.3.0/
    I would do a clean install. Than install all apps from scratch.
    Upgrade CS5 first ahead of time if you want Migration or Setup Assistant.
    Clone your system:
    How to Clone a Volume
    Using Cloning as a Backup Strategy 
    See also Erasing a Drive, How and Why to Partition a Drive, RAID.
    http://www.macupdate.com/app/mac/7032/carbon-copy-cloner
    Using Cloning as a Backup Strategy
    http://macperformanceguide.com/Mac-HowToClone.html
    Sorry you felt the need to start a new thread.
    No need to single out and title a thread with anyone's name.

  • DVD-R vs DVD+R/ Whats the Difference & What should i use w Macbook

    i have the latest macbook. been using dvd-r and was always curious. can i use DVD+ ?
    whats the difference?
    thanks

    http://www.dvd-supply.com/whisdvdvdvan.html
    Your MacBook will burn both.
    -Bmer
    Mac Owners Support Group
    Join Us @ MacOSG.com
    YouTube.MacOSG.com
    iTunes: MacOSG Podcast
     An Apple User Group 

  • Does any one know how to get smileys for Facebook on the mac,, i see people using them all the time and don't know how to do it,,,

    I know this is a bit of a strange question, but i have seen people using the smileys on face book, but every time i try to get them they dont work, i was just wondering if any one knew how, i thought i would put it on here as i have got a lot of helpful tips on here for alot of problems and you guys know what you are talking about,,,

    not 100% sure what you mean
    smileys are a sequence of chars like ;-¶ which the internet site or program like a chat program replace with an image typically a small gif image
    is your problem that you want to save those images to your harddisk?
    is your problem that you wish some other program then facebook to replace the smiley chars with the images that facebook use?
    is your problem that when you type on facebook your smileys are not replaced with the same images as others (in which case you should prob as which signs they type)

  • No wi/fi iPhone 4S and no help apple thanks for all the hrs on the phone and letting me use up all my Internet doing what y'all said do and not fits yeah been going on for months and it only mess up each time y'all ask to up date and I'm at 6.1.3

    WHy did y'all let me wast my time trying to fix this phone and use up my Internet on here and at home when all everyone that has IPhone has the same problem that I do ? And it's every time y'all add a update I'm at 6.1.3 and that's 3 updates from the time I had got this phone replace in oct and been out of wi/fi two months now and all the reboots from oct I had to do

    This is a user to user help forum only. You are not addressing Apple here.
    My iPhone 4S, iPhone 5, and iPad 2 are running 6.1.3 with no such problem and the same with the overwhelming majority of iOS devices running 6.1.3.

  • Why do I not see the transition confetti and the water droplet? i used it all the time in the old version but do not see it in Keynote 09

    what happend to the confetti and the water droplet transitions?  I can't find them in the 09 version of keynote?

    Try:
    "Preferences", "General", and select "Animations: Include obsolete animations in choices".
    I hope that does it!

  • Use of final keyword on methods arguements ?

    Hi All,
    Just say I have an input arguement for a method which is an int. If I wanted to access the value stored by the input arguement reference inside an anonymous class that is contained in the method one way would be to pass the input arguement reference to a instance variable of the class that contains the method and use that.
    // Declared at start of  class
    int arrayIndex = 0;
    methodName(nt inputNumber)
        arrayIndex = inputNumber;
        ActionListener task = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                // Accessing here
                anArray[arrayIndex] = 100;
    }Just wondering, I used the final keyword on the the input arguement instead and then used the input arguement directly instead. It seemed to work ok. Is this good programming practice or are there some pitfalls to using this that I'm not aware of?
    (I don't need to change what the input arguement reference points to)
    // Alternate
    methodName(final int inputNumber)
        ActionListener task = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                // Accessing here
                anArray[inputNumber)] = 100;
    }Regards.

    declaring it final guarantees that you will not change the value.Of course it does. That's what it's for. That's what it means. But you're only guaranteeing that to yourself. It doesn't form part of the interface contract so it's no use to anybody else. Which is the bigger picture.
    Whenever i use any anonymous classes i prefer to use the final variables as long as i dont need to change their values.No you don't 'prefer' it, you are forced to do that by the compiler.

  • Help needed understanding final keyword and  use 3

    Hi Everyone,
    I have been studying a book on multi-threading and have inadvertently come accross some code that I don't really understand. I am wondering if anybody can explain to me the following:
    1). What effect does using the final keyword have when instantiating objects, and
    2). How is it possible to instantiate an object from an interface?
    public class BothInMethod extends Object
         private String objID;
         public BothInMethod(String objID)
              this.objID = objID;
         public void doStuff(int val)
              print("entering doStuff()");
              int num = val * 2 + objID.length();
              print("in doStuff() - local variable num=" + num);
              // slow things down to make observations
              try{
                   Thread.sleep(2000);
              }catch(InterruptedException x){}
              print("leaving doStuff()");
         public void print(String msg)
              String threadName = Thread.currentThread().getName();
              System.out.println(threadName + ": " + msg);
         public static void main(String[] args)
              final BothInMethod bim = new BothInMethod("obj1");  //Use of final on objects?
              Runnable runA = new Runnable()      //Creating objects from an interface?
                   public void run()
                        bim.doStuff(3);
              Thread threadA = new Thread(runA, "threadA");
              threadA.start();
              try{
                   Thread.sleep(200);
              }catch(InterruptedException x){}
              Runnable runB = new Runnable()
                   public void run()
                        bim.doStuff(7);
              Thread threadB = new Thread(runB, "threadB");
              threadB.start();
    }If you know of any good tutorials that explain this (preferably URL's) then please let me know. Thanks heaps for your help.
    Regards
    Davo

    final BothInMethod bim = new BothInMethod("obj1");  //Use of final on objects?
    Runnable runA = new Runnable()      //Creating objects from an interface?          
         public void run()               
                                    bim.doStuff(3);               
    };Here final is the characteristics of bim reference variable and it is not the characteristics of class BothInMethod
    This means u cannot use bim to point to some other object of the same class
    i.e, u cannot do this
                       final BothInMethod bim = new BothInMethod("obj1"); 
                       bim  =  new   BothInMethod("obj2");  This bim is a constant reference variable which will point only to the object which it is initialized to
    and not to any other object of the same class later on.
    How is it possible to instantiate an object from an interface?Regarding this yes we cannot create an object from an interface but
    but here it is not an interface u are providing the implementation of the interface Runnable
    as
    new Runnable()
    }This now no longer stays an interface but now it is an object that implements the interface Runnable

Maybe you are looking for

  • IPod touch 4g won't show up in iTunes

    My iPod4g won't show up in iTunes at all. I've tried uninstalling and re-downloading the newest iTunes, I've uninstalled the iPod driver, idk what else to do. since I use a secondary music app cause apples is terrible I just upload my music to skydri

  • OM:Cost of Goods sold work flow customization to take it from concerned off

    OM:Cost of Goods sold work flow customization to take it from concerned office in the place of inventory org

  • Dead Hard Drive in PB12?

    I'm a longtime Mac owner and have never experienced any serious hard drive problems, so I'm not sure what I'm dealing with on my PB12 right now. Lately, when I boot, my PB sounds like it has "marbles" inside pinging around. It still booted; just took

  • Check for mat transfer in thro 541 to SC Vendor if it exeeds the PO qty

    Dear Friends, user is able to transfer material to sub contractor through 541 movementwith reference to PO  if the qty exceeds the PO qty. How can it be stopped ? Is there any error message to be set ? Pl provide me the solution. Regards, ASK

  • Can't Modify WCS Report File Destination

    Once I upgraded to WCS 6.0.132.0 I can no longer change the destination file location when I run reports. The reports seem to run on schedule but they end up in the default location of C:\WCSFTP\reports\. I would like to change that to my E: where I