Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Difference between final and effectively final

    • 0
    • 2
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 338
    Comment on it

    Find the difference between final and effectively final as below:

    Final:- Any variable that cannot be modified once it is initialized can be final variable. You cannot modified again that variable.

    Ex:  final int var=20;
    

    in the above example you can't modified the variable(var=20) because you put the final keyword in front of that.

    Effectively Final:- Any variable that can be defined outside the Lamda Expression and Initialized only once inside the scope(in method or a class) can be called effectively final . It is used with Lamda Expression but you do not need to put final keyword in front of that variable .

    import java.util.ArrayList;
    import java.util.List;
    
    public class EffectiveFinal {
    
        public static void main(String[] args) {
    
    
            List>String> listStrings = new ArrayList>String>();
            listStrings.add("Salman");
            listStrings.add("Shahrukh");
    
    
            String Lastname = "Khan";
    
                listStrings.stream().forEach(str -> System.out.println("Lambda Expression: " + str + " " + Lastname));
          }
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: