Difference between these primarily is that
boolean[] cameraPermissionGranted = {false};
is an array that persists boolean
type of data initialized with single element false
at present unless resized(re-initialized) while
boolean cameraPermissionGranted = false;
is just an attribute that is initialized as false
and can be updated thereafter.
One of the very intuitive example that comes to my mind for that is usage in lambda’s :
boolean[] cameraPermissionGranted = {false};
boolean cameraPermission = false;
List<Integer> list = new ArrayList<>();
list.forEach(a -> {
cameraPermissionGranted[0] = true; // effectively final
// cannot use cameraPermission
});
1
solved Difference boolean[] b = {false} vs. boolean b = false? [closed]