Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is this Java syntax? → CLASS.<PARAMETER_TYPE>STATIC_FUNCTION_NAME()

I was reading FirebaseUI library source code when I stumbled upon syntax I hadn’t seen before.

It was first folded by IntelliJ IDEA:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Then I had to click it to unfold:

enter image description here

What is this line?

setScopes(Collections.<String>emptyList());

Is it equal to this?

setScopes(Collections.emptyList<String>());

If it is, why was it written that way? Is it the same thing as with two ways of declaring an array in Java?

  1. Java way:
char[] letters = new char[100];
  1. C way:
char letters[] = new char[100];

(Both are acceptable.)

>Solution :

setScopes(Collections.emptyList<String>()); would be invalid, since an explicit generic type argument needs to be at the start of a method call, like shown in your other examples.

If there’s a method that wants a generic argument, but the compiler can’t make out what you want that generic argument to be, you need to specify it yourself using the syntax above. Think of it like an equivalent to new ArrayList<String>(), except for method calls: this.<String>someMethod()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading