-3

I've got a constructor that takes a parameter ArrayList<Setting> settings.

Now the problem is that I wrote the following call in a subclass:

super(new ArrayList<Setting>(){new Setting("", this, 0)});

This causes a lot of errors, the main one being Invalid method declaration; return type required, as well as '{' or ';' expected, Parameter expected, Unexpected token and Constructor Setting() is never used.

I tried switching to using regular arrays and it worked fine:

super(new Setting[]{new Setting("Exp Only", this, false)});

For now, I'm happy just using regular arrays, however I come across this error rather frequently, is there something I'm doing wrong or is this just the way it is, and if so, why?

1 Answers1

1

Java has introduced of method since java 9. You can use it as below.

super(List.of(new Setting("Exp Only", this, false)));
parthivrshah
  • 634
  • 2
  • 7
  • 14