Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6098461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:09:39+00:00 2026-05-23T13:09:39+00:00

The following is supposed to be part of Java 1.7: List<String> list = [item];

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:09:40+00:00Added an answer on May 23, 2026 at 1:09 pm

    You are referring to two distinct features of Project Coin that were NOT accepted for inclusion in JDK 7.

    1. Support for Collection literals

      SomeClass a;
      SomeClass b;
      List<SomeClass> list = [a, b];
      Map<String, SomeClass> map = { "key1": a, "key2": b };
      Set<SomeClass> set = { a, b };
      

      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.

    2. Indexing access syntax for Lists and Maps

      List<SomeClass> l = new ArrayList<>();
      SomeClass first = new SomeClass();
      l[0] = first; // instead of l.set(0, first);
      SomeClass retrieved = l[0] // instead of l.get(0);
      // Similar thing for maps.
      

      That is the feature which is implemented in C# as indexed properties, and it only applies to the List and Map interfaces (remember that, contrary to the .NET Class Library, the Java interfaces are not usually prefixed with an I) – 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:

    • For the first feature, the compiler will transform the literal into a call to a few methods to create a unmodifiable List, Set or Map. (I seem to remember that the concrete classes that are returned are not even publicly visible.)
    • For the second feature, the compiler will just transform the expression into calls to the relevant methods, as long as the class implements the List or Map interface.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following line is supposed to print a list item which is a variable
The following snippet is supposed to take the value of PROJECT (defined in the
The following snippets are both supposed to calculate sha-1 sum. But for the same
Supposed I have the following string: string str = <tag>text</tag>; And I would like
Let´s say I´ve got the following xml string: <Item Name=\$Resources:myresource,somestring;\</Item> Now I want to
I get the following error when I try to run my java program(it's supposed
I am creating a SMS app the following code is supposed to: check if
I have the following method that is supposed to be a generic Save to
Given the following code (it's supposed to write helloworld in a helloworld file, and
I have the following XAML, that does all that it is supposed to, except

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.