Friend, I pray that you are going to at least Java 17 and not to 11 lol. Heck, if you can wait a few months 21 will be out and you'll have virtual threads! (Actually I can't remember if it is a preview in 21 or not off the top of my head.)
// As of Java 21
static String formatterPatternSwitch(Object obj) {
return switch (obj) {
case Integer i -> String.format("int %d", i);
case Long l -> String.format("long %d", l);
case Double d -> String.format("double %f", d);
case String s -> String.format("String %s", s);
default -> obj.toString();
};
}
7 Comments
Akisamb@programming.dev · 7 pts · 3y
I imagine that everybody in this community has seen this JEP, but I'm just so happy that we finally have exhaustive pattern matching in java.
My job has also announced a multi-million plan to get rid of websphere and java 8, so maybe I may even see these features at my job one day ^^
lowleveldata@programming.dev · 6 pts · 3y
haha, I was going to say "cool feature but I'm still on Java 8 / 11"
JackbyDev@programming.dev · 3 pts · 3y
In 2014 my first job as a junior developer we were on Java 6 on WebSphere. We didn't even get try-with-resources lol.
MagicShel@programming.dev · 2 pts · 3y
I think in 2014 I was working on Java 5. Then maybe 5 years later we went to 7. Then I changed jobs to a place on 6. Then we migrated to 8.
Since then I think I've had one project on Java 11 and everything else has been Java 8.
I do have a persona side project on Java 20, at least.
JackbyDev@programming.dev · 4 pts · 3y
Friend, I pray that you are going to at least Java 17 and not to 11 lol. Heck, if you can wait a few months 21 will be out and you'll have virtual threads! (Actually I can't remember if it is a preview in 21 or not off the top of my head.)
Akisamb@programming.dev · 2 pts · 3y
The target is 17 at the moment, but I'm keeping hope for version 21.
JackbyDev@programming.dev · 3 pts · 3y
Example code from the link for the lazy,