BenCes
BenCes

Reputation: 165

Whats wrong with this error? Syntax error on token "<", ? expected after this token

I have this line of code in my Java program:

private final List<PhoneNumber> receivers = new ArrayList<>();

It signifies an error underneath the first < after 'new ArrayList'. ^

I'm running Eclipse and Windows 8 - 32-bit, could this be an encoding problem?

Upvotes: 1

Views: 6569

Answers (3)

BenCes
BenCes

Reputation: 165

This was the solution for me:

  • Window -> Preferences -> Java -> Compiler -> Compiler Compliance Level: 1.7

this was 1.6 at first.

Had to download Eclipse Indigo RS2 for this one.

Upvotes: 0

Qkyrie
Qkyrie

Reputation: 939

The Diamond Operator, used to reduce the verbosity when using generics was added in JDK 1.7. The fact you're getting a syntax error probably means you're using an older version to compile this piece of code.

Either use JDK 1.7 to compile the code, or change to:

new ArrayList<PhoneNumber>();

Upvotes: 1

Achintya Jha
Achintya Jha

Reputation: 12843

Try this: You have to parametarize the type of object at both sides.

private final List<PhoneNumber> receivers = new ArrayList<PhoneNumber>();

Upvotes: 3

Related Questions