The following is supposed to be part of Java 1.7:
List<String> list = ["item"];
String item = list[0];
Set<String> set = {"item"};
Map<String, Integer> map = {"key" : 1};
int value = map["key"];
The same can pretty much be done in C# (and VB.NET) with a slightly difference syntax. In .NET, this is implemented as indexed properties, which is a language feature any developer can use to apply onto own classes.
Does anyone know if these feature are strictly hardcoded for List, Set, and Map and subclasses or there is a more general language feature behind this?
You are referring to two distinct features of Project Coin that were NOT accepted for inclusion in JDK 7.
Support for Collection literals
It should be noted that these literals only allow for the creation of unmodifiable (read-only in .NET) collections. As far as I know, such literals do not exist in C# (except for arrays, but such literals have also existed in Java for a long time). It also does not have anything to do with indexed properties.
Indexing access syntax for Lists and Maps
That is the feature which is implemented in C# as indexed properties, and it only applies to the
ListandMapinterfaces (remember that, contrary to the .NET Class Library, the Java interfaces are not usually prefixed with anI) – it is nothing more than a transformation, by the compiler, into calls to these methods.In both cases, there is no general language feature, just a bit of syntactic sugar:
List,SetorMap. (I seem to remember that the concrete classes that are returned are not even publicly visible.)ListorMapinterface.