javalistgenericsdiamond-operator

illegal start of type error about my code


While I am creating a load , my program gives below error ;

D:\views\UniqueAcctStorageRuleNameValidator.java:34: illegal start of type
List<String> listOfAcctStorageRuleNameAsArray =
    new ArrayList<>(listOfAcctStorageRuleName.size());

Here is the code;

public class FKAcctStorageRuleNameValidator extends AbstractAnnotationCheck<FKAcctStorageRuleName>{

   private static final long serialVersionUID = 1L;

   private SpecbookValidatorManager specBookValidator;   

   @Override
   public boolean isSatisfied(Object validatedObject, Object valueToValidate,
           OValContext context, Validator validator) throws OValException {
      if (valueToValidate == null) return true;

      specBookValidator = SpecbookValidatorManagerImpl.getInstance();

      List<SpecbookAcctStorageRule> listOfAcctStorageRuleName = specBookValidator.getAcctStorageRuleList();

      List<String> listOfAcctStorageRuleNameAsArray = new ArrayList<>(listOfAcctStorageRuleName.size());
      for (SpecbookAcctStorageRule specbookAcctStorageRule : listOfAcctStorageRuleName) {
         listOfAcctStorageRuleNameAsArray.add(specbookAcctStorageRule.getName());
      }

      return ListUtil.containsIgnoreCase((String) valueToValidate, listOfAcctStorageRuleNameAsArray);
   }
}

Solution

  • It’s likely that you are using the JDK a version which is lower than 7. It doesn't know what the diamond <> is.

    Changing to the following will solve the issue:

    new ArrayList<String>(listOfAcctStorageRuleName.size());
    

    Of course, you are free to download a newer Java version to use all convenient features that are not allowed in the previous ones.