prilia
prilia

Reputation: 1016

Java 1.7 - generic error syntax

I get from github java project. I have java 1.7 version
there is code like this:

    protected Set<Tag> tags = null;
    private final Map<Tag, String> results;    
    protected AbstractAction() {
        this.tags = new HashSet<>();
        this.results = new HashMap<>();
    }

I added it to eclipse, but there is error on new HashSet<>();

The error in eclipse is :

Multiple markers at this line - Cannot instantiate the type HashSet - Syntax error on token "<", ? expected after this token - Type mismatch: cannot convert from HashSet to Set - Syntax error on token "<", ? expected after this token

How do you think I can resolve it ? Thank you.

Upvotes: 1

Views: 397

Answers (1)

Joni
Joni

Reputation: 111349

The type inference feature was introduced in Java 7, and your code compiles correctly using the Java 7 JDK. Make sure you have configured the Java version level in the Eclipse project for Java 7 and not some earlier version.

Upvotes: 2

Related Questions