If finally
block executes before return statement present in side try block
, then why return list
is not printing null
instead printing [DEV].
public class Sub {
List list = new ArrayList();
public List check(){
try {
list.add("DEV");
return list;
}finally{
list = null;
System.out.println("Inside finally ["+list+"]");
}
}
public static void main(String[] args) {
Sub sup = new Sub();
System.out.println(sup.check());
System.out.println(sup.list);
}
}
O/P:
- Inside finally [null]
- [DEV]
- null