final keyword

Discussion in 'Serialization' started by Sudhanshu306, May 11, 2015.

  1. Sudhanshu306

    Sudhanshu306 New Member

    Can we use final for passed parameter?
     

  2. cool_one368

    cool_one368 New Member

    Very Good Question Indeed. Surprised to not to see the answer of this.

    For this we will take an example of a setter method. Please see the same below:

    Code:
    public void setTest(String test) {
        test = test;
    }
    
    Now suppose i forgot to add the "This" keyword over here. What will happen here is the variable that you are trying to set here will not be set. Now if i Add the final keyword on the parameter. This would give me a compile time error and I will get to know that there is something wrong here. Which helps in understanding. Hope it helps.
     

Share This Page