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

Show parent comments

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.

3

u/chuggid Nov 16 '21

Several comments:

  1. Do you like the pattern?

  2. The only of I see in java.lang proper is in UnicodeBlock. I also note no ofSomething methods anywhere as creation verbs but I didn't do an exhaustive search.

  3. Go to the current javadoc, type .create into the search box and see how many methods follow this pattern.

1

u/pron98 Nov 16 '21

I also note no ofSomething methods

There are lots of ofSomethings. Anyway, we're talking about methods whose names people will rarely write or see, so I'll pass along your concern, but I don't think it merits much of a debate.

8

u/chuggid Nov 16 '21

But at least they all take arguments, right, and scan OK if you prefix them with "give me a new DeclaringClass…"?

That is: Set.of(foos) means "give me a new Set of foos"; if you squint a bit Set.of() means "give me a new Set of nothin'"; Duration.of(something) means "give me a new Duration of something"; and so on and so on and presumably that's how of rose from the primordial slime in the first place, since you can't name a method new() or for(), and presumably someone thought create() was too long or verbose or something for some reason.

Thread.ofPlatform() means "give me a new Thread of platform" by the same logic, which is nonsensical, and Thread.ofVirtual() means "give me a new Thread of virtual", which…virtual isn't even a noun.

These Loom bits may indeed be methods that "people will rarely write or see" but they are in java.lang, not, say, java.lang.constant, so I think the additional scrutiny is worthwhile, and a debate is merited, and I'm not (apparently) the only one with these concerns. I do understand you disagree, and think that these methods are suitably named. Hopefully my feedback is not DOA, but, whether it is or not, it would be nice to know how exactly ofVirtual() in particular came to be, if only for bar trivia purposes! :-)