Tagir Valeev

@tagir_valeev@mastodon.online
739 Followers
53 Following
883 Posts
AboutWork at JetBrains. Java Champion. Check my Java book: https://mng.bz/671p
Twitterhttps://twitter.com/tagir_valeev
LinkedInhttps://linkedin.com/in/tagir-valeev

#Java peers...the 2025 @intellij IDEA Conference is around the corner (June 3-4)! There's still time to register for this FREE virtual event: https://lp.jetbrains.com/intellij-idea-conf-2025/

Hear from host @maritvandijk and me as we kick things off to celebrate 30 YEARS OF JAVA!

IntelliJ IDEA Conf 2025 | June 3-4, 2025

We invite you to join us for IntelliJ IDEA Conf 2025 and gain insights from industry leaders and experts.

JetBrains: Developer Tools for Professionals and Teams

Puzzler of the week (inspired by @tagir_valeev)

How many of the following have value "%"?

"%%".formatted()
"%1%".formatted()
"%-1%".formatted()
"%1$1%.formatted()

One
22.2%
Two
22.2%
Three
22.2%
All four
33.3%
Poll ended at .
TIL: In #Java format strings, you can specify indentation to a single percent character.
30 Years of Java

YouTube
Here's how the analytics for a single flaky test looks like inside the IntelliJ project.
And it prints 'From var'. However, you can remove the variable declaration, and it will resolve to a class and print 'From class'. There's no ambiguity, as an instance-bound method reference has a priority over a statically bound one.

You can try something simpler, e.g.

void main() {
class C {
static void run() {
System.out.println("From class");
}
}
Runnable C = () -> System.out.println("From var");

Runnable r = C::run;

r​.run();
}

IDE resolves C properly to a variable.

One of the few places where both class name and variable name can appear is the method reference qualifier. In this case, first it's assumed to be an expression (variable reference), and if it doesn't work, then there's an attempt to resolve a class. If the variable works, we don't try a class.
The correct answer is counter-intuitively, Outer2​.foo. Normally, classes and variables have separate namespaces in Java, so importing class and importing variable (static field) with the same name does not produce an ambiguous import.

Ok, here's my solution. Full of warnings, of course, but who cares about warnings?

void main() {
O<O<O>> O = O<O>::<O>O;
}

interface O<T> {
void use(O c);

default <C> void O() {
}
}
https://mastodon.online/@tagir_valeev/114335110570765456

Tagir Valeev (@tagir_valeev@mastodon.online)

Provide the declaration of the O type, so this statement could be a valid #Java statement: O<O<O>> O = O<O>::<O>O;

Mastodon