Tagir Valeev
Tagir Valeev boosted:
Sharat ChanderSharat_Chander
2025-06-02

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

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

Tagir Valeev boosted:
2025-06-02

Puzzler of the week (inspired by @tagir_valeev)

How many of the following have value "%"?

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

2025-05-26

TIL: In #Java format strings, you can specify indentation to a single percent character.

jshell> System.out.printf("%10%%10%\n")
         %         %
$1 ==> java.io.PrintStream@21213b92
2025-05-22

@andrybak yes, you can filter or partition failures by OS

2025-05-22

Here's how the analytics for a single flaky test looks like inside the IntelliJ project.

2025-04-15

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.

2025-04-15

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.

2025-04-15

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.

2025-04-15

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.

2025-04-15

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() {
}
}
mastodon.online/@tagir_valeev/

2025-04-14

@0x1ac quite close!

2025-04-14

Btw ChatGPT 4o cannot solve it for me (using the post above as the prompt). You have a chance to be smarter than AI :-)

2025-04-14

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

O<O<O>> O = O<O>::<O>O;

Tagir Valeev boosted:
Benjamin Marwell β˜•bmarwell@layer8.space
2025-04-12

@tagir_valeev

I can highly recommend this book. Even though I think I've seen a lot of the discussed mistakes, it's good to read about it, and there's a lot of additional helpful information. Plus the mistakes you hadn't on your mind.

Tagir Valeev boosted:
Benjamin Marwell β˜•bmarwell@layer8.space
2025-04-12

Well, I didn't fall for Mistake #11 from @tagir_valeev book, but quite something similar:
Jackson Objects are both mutable AND return the updated self. I took it for being a copy-then-modify-Operation and used the original value elsewhere - which was modified, too. 😬

#java #mistakes

Tagir Valeev boosted:
2025-04-11

@tagir_valeev This one is also pretty interesting: github.com/TodePond/GulfOfMexi

2025-04-11

So what would you expect (please answer before you actually try!)

2025-04-11

What is the output of this Java code? (poll follows)

package com.example;

public class Outer {
  public static class Inner {
      public static void foo() {
        System.out.println("Outer.Inner.foo");
      }
  }
}
package com.example;

public class Outer2 {
    public static final Outer2 Inner = new Outer2();

    public void foo() {
        System.out.println("Outer2.foo");
    }
}
import static com.example.Outer.Inner;
import static com.example.Outer2.Inner;

class Main {
    public static void main(String[] args) {
        Runnable r = Inner::foo;
        r.run();
    }
}
2025-04-09

Two lines of code eat too much of time in a user-supplied CPU profile. These lines exist for ages. It's not so clear why they were added. Let's just remove them🀞

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst