In a project, I see the following code:
//f is a File
boolean acceptable = true;
acceptable &= sweepFilename != null;
acceptable &= f.getName().equals(sweepFilename.toString()); // parsable
acceptable &= id == null || id.equals(sweepFilename.getId());
acceptable &= length == null || length.equals(sweepFilename.getLength());
acceptable &= f.getName().toLowerCase().endsWith(SweepFilename.EXTENSION);
acceptable |= f.isDirectory();
return acceptable;
Can someone explain me what the &= and |= means?
I understand it as, if acceptable is true then also check the right side and assign the value of the operation (false/true) to acceptable, so that if it is false, then it will not need to check the right side.
x &= y;=x = x & y;&in turn is the bitwise AND operator.