0

I would like to make an ArrayList which contains Objects.

ArrayList<Object> objects = new ArrayList<Object>();

The code is underlined and NetBeans says: "Redundant type arguments in new expression (use diamond operator instead)."

What does it mean?

JuanMoreno
  • 2,498
  • 1
  • 25
  • 34
hazazs
  • 39
  • 1
  • 8
  • 1
    It means that you can remove `Object` on the right side of the assignment. Like this: `ArrayList objects = new ArrayList<>();` – marstran Jan 14 '20 at 20:14
  • 1
    `List objects = new ArrayList<>();` you don't need to repeat `Object`, the compiler can infer it, therefore it is redundant. `<>` is the diamond operator – Bentaye Jan 14 '20 at 20:15
  • Partly yes, thank you. – hazazs Jan 15 '20 at 09:16

1 Answers1

2

It means you can rewrite the line of code like this:

ArrayList<Object> objects = new ArrayList<>();

and it will work the same.

Ryan Hand
  • 71
  • 4