JDK-8160311 : Collection initialization
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 9
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2016-06-26
  • Updated: 2016-06-27
  • Resolved: 2016-06-27
Related Reports
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
We can initialize Arrays like  Integer i = {1,2,3,4}. However, same thing is possible on Collections like List, Set and Maps. I would recommend to allow this feature on Collections too.

For example:
List<Integer> list = new ArrayList(){1,2,3,4} or new ArrayList(1,2,3,4,...).
Map<String,Integer> map = new HashMap(){ "1":1,"2":2,"3":3,..}

This will be very helpful especial, when writing testing cases, and we have to create parallel collections to assert/validate test cases 


JUSTIFICATION :
When we have to create a Collection with small/medium amount of known data, especially when writing test cases. we have to call add() again and again many times or create a parallel collection to assert the test case values. This will result in lot of code in Fixture, this feature will be very handy and can solve this problem very effectively





Comments
"JEP 269: Convenience Factory Methods for Collections (JDK-8048330)" handles pretty much what the submitter is looking for. Closing it as duplicate of JDK-8048330.
27-06-2016