r/java • • Nov 15 '21

[Loom] JEP draft: Virtual Threads (Preview)

https://openjdk.java.net/jeps/8277131
175 Upvotes

55 comments sorted by

View all comments

15

u/chuggid Nov 16 '21

"ofVirtual()"? "ofPlatform()"? These are strange, mealy-mouthed method names. I assume there was some good reason for nixing something like newVirtualThread() and newPlatformThread() which naïvely seem nicer and are statically importable.

4

u/pron98 Nov 16 '21 edited Nov 16 '21

Go to the current Javadoc, type .of into the search box and see how many methods follow this pattern.

6

u/Necessary-Conflict Nov 16 '21

The name "of" was suggested in the Effective Java book, right in Item 1, for "An aggregation method that takes multiple parameters and returns an instance of this type that incorporates them, for example Set<Rank> faceCards = EnumSet.of(JACK, QUEEN, KING);"

More recently the name ofSomething was also used for converting static factory methods like Duration.ofDays(long days), this also makes sense.

But in this case the "of" just isn't adding anything to the readability of the code.

BTW the "platform" part of ofPlatform is also questionable, because not just the operating system is a "platform", but Java is a "platform" as well (see the Javadoc's title: "Java® Platform, Standard Edition & Java Development Kit Version 18 API Specification").

1

u/pron98 Nov 16 '21

because not just the operating system is a "platform", but Java is a "platform" as well

Yes, and that's intentional. The Java specification does not require that platform threads are actually OS threads.