0
What's the impact when list is final.?
What happen when we declare list as final as below final List <String> list=new ArrayList();
1 Answer
+ 15
Nothing was happen but if you add another memory address in (list) variable than compiler throw error becz the variable (list) is final and you cant assign another memory address in list veriable
Example
This code run without any error
ArrayList<Integer> obj = new ArrayList<>();
// add an another memory address
obj = new ArrayList<Integer>();
Compiler error
final ArrayList<Integer> obj = new ArrayList<>();
// add an another memory address
obj = new ArrayList<Integer>();