What’s wrong with my syntax here?
boolean isValid() = false;
policyHolder().getYear().matches("^\\d{4}$") ? isValid = true : isValid = false;
Note: policyHolder().getYear() is a String.
I’m checking the year value has 4 digits but get an error saying Variable expected.
>Solution :
Use ternary operator in correct way:
isValid = policyHolder().getYear().matches("^\\d{4}$") ? true : false;
Or simply:
isValid = policyHolder().getYear().matches("^\\d{4}$");