Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java: represent arrays as UnmodifiableList #722

Closed
1 of 4 tasks
RomainMuller opened this issue Aug 20, 2019 · 3 comments · Fixed by #765
Closed
1 of 4 tasks

java: represent arrays as UnmodifiableList #722

RomainMuller opened this issue Aug 20, 2019 · 3 comments · Fixed by #765
Labels
effort/medium Medium work item – a couple days of effort feature-request A feature should be added or improved. language/java Related to Java bindings p0

Comments

@RomainMuller
Copy link
Contributor

🚀 Feature Request

Affected Languages

  • TypeScript or Javascript
  • Python
  • Java
  • .NET (C#, F#, ...)

Description

Since the JSII kernel currently doesn't support ways to propagate array mutations through the language border, and that the List API in Java is quite large, using immutable collections would be safer from Java's standpoint as it makes no unmet guarantees to the user.

@RomainMuller RomainMuller added language/java Related to Java bindings feature-request A feature should be added or improved. p0 labels Aug 20, 2019
@RomainMuller RomainMuller added this to the Java Support milestone Aug 20, 2019
@RomainMuller RomainMuller added the effort/medium Medium work item – a couple days of effort label Aug 20, 2019
@McDoit
Copy link

McDoit commented Aug 31, 2019

I assume the same would also be applied to dotnet?

With https://devblogs.microsoft.com/dotnet/immutable-collections-ready-for-prime-time/ maybe?

@RomainMuller
Copy link
Contributor Author

That'd be nice. @assyadh any opinion?

@assyadh
Copy link
Contributor

assyadh commented Sep 3, 2019

That'd be nice. @assyadh any opinion?

It is doable, but there is no constructor associated with ImmutableList.
Customers need to retrieve the list by calling ImmutableList.Empty
Then adding their values. Feels tedious to me:

    class Test
    {
        public ImmutableList<string> MyProperty { get; set; }
    }


     class Program
    {
        static void Main(string[] args)
        {
            // First way of doing it
            var values = new List<string> { "first", "second" };
            var list = ImmutableList<string>.Empty;
            list = list.AddRange(values);
            var test = new Test()
            {
                MyProperty = list
            };

            // Inline initialization
            var test2 = new Test()
            {
                MyProperty = ImmutableList<string>.Empty.AddRange(values)
            };
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/medium Medium work item – a couple days of effort feature-request A feature should be added or improved. language/java Related to Java bindings p0
Projects
None yet
3 participants