[ 
https://issues.apache.org/jira/browse/SOLR-17027?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17775830#comment-17775830
 ] 

Uwe Schindler commented on SOLR-17027:
--------------------------------------

bq. Just because I didn't know about it and Intellij didn't suggest it  Will 
keep it in mind going forward.

No problem. Everyday you learn something new :-) Same here! The IDE suggestions 
are often outdated. This reminds me on the well-known Eclipse 
{{e.printStackTrace()}} automatic try-catch implementation all students use and 
one of the reasons forbiddenapis was invented :-)

In my opinion, the method reference to the array constructor is the most 
universal and type-safe way, so it has several opportunities:
- You do not need to decide how to create the array so the whole discussion in 
the article cited above is obsolete. You just pass the generator for the array 
and let java do the right thing (the list/collection impl can decide if they 
want to create the array with final size, or create it whatever they think is 
best).
- It automatically returns the correct array type in a type-safe way. SO it 
looks very elegant.

By the way, in the Java 8 stream API they intruduced that mechanism tocollect 
results into arrays for streams as the onlyoption. There is no way to pass an 
instance of pre-allocated arrays, so based on this, the above code is "legacy".

> Removing list.toArray calls with pre sized arrays
> -------------------------------------------------
>
>                 Key: SOLR-17027
>                 URL: https://issues.apache.org/jira/browse/SOLR-17027
>             Project: Solr
>          Issue Type: Task
>            Reporter: Kevin Risden
>            Assignee: Kevin Risden
>            Priority: Minor
>             Fix For: main (10.0), 9.5
>
>          Time Spent: 1h 20m
>  Remaining Estimate: 0h
>
> Removing list.toArray calls with pre sized arrays
> https://www.baeldung.com/java-collection-toarray-methods



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to