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

Add convenience factory methods to create NSDictionary, NSArray, and NSSet #933

Conversation

hprange
Copy link
Contributor

@hprange hprange commented Jul 4, 2020

As per JEP 269, Java 9 defined library APIs to make it convenient to create instances of collections and maps with small numbers of elements. This pull request introduces a similar concept for NSDictionary, NSArray, and NSSet. It provides convenience factory methods to create NSCollections in a less verbose, concise, and uniform way.

Usage:

NSDictionary<String, String> dict = NSDictionary.of("k1", "v1",
                                                    "k2", "v2");

NSArray<String> array = NSArray.of("e1", "e2", "e3");

NSSet<String> set = NSSet.of("e1", "e2");

…nd NSSets

As per [JEP 269](https://openjdk.java.net/jeps/269), Java 9 defined library APIs to make it convenient to create instances of collections and maps with small numbers of elements. This pull request introduces a similar concept for NSDictionaries, NSArrays, and NSSets. It provides convenience factory methods to create NSCollections in a less verbose, concise, and uniform way.

Usage:

```java
NSDictionary<String, String> dict = NSDictionary.of("k1", "v1",
                                                    "k2", "v2");

NSArray<String> array = NSArray.of("e1", "e2", "e3");

NSSet<String> set = NSSet.of("e1", "e2");
```
@hprange hprange added the Wonder7 label Jul 4, 2020
@luizalfredo23
Copy link
Contributor

luizalfredo23 commented Jul 8, 2020

I can't wait to save some lines of code by creating an NSArray with some items in just one line, countless times when I could have used it.

And of course, creating NSDictionary would be a lot easier.

@darkv
Copy link
Member

darkv commented Jul 8, 2020

@luizalfredo23 with the Wonder versions of those classes this was already possible since long ago like
NSArray<String> array = new NSArray("e1", "e2", "e3");

@luizalfredo23
Copy link
Contributor

@darkv

@luizalfredo23 with the Wonder versions of those classes this was already possible since long ago like
NSArray<String> array = new NSArray("e1", "e2", "e3");

With Java 11 I've been using List.of so I think it would be nice using NSArray.of, but I did not know about the constructor, I'm using it right now. Thanks.

No changes to the business logic.
@darkv darkv merged commit 55d8ccd into wocommunity:master Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants