Language selector

Little Java riddle

Below you can find a piece of code written in Java. I’d like to ask you one thing: please don’t run this code before you try to answer.

Copying this code into jshell takes just a few seconds, but then the knowledge may last for a few seconds as well…

I suggest a little thought experiment, reading Javadoc, running this mentally in your mind…

19import java.util.*;
21public class Riddle {
23	public static void main(String[] args) {
24		var raz = List.of("checking!");
25		var dwa = List.copyOf(raz);
26		if (raz == dwa) {
27			System.out.println("ene");
28		} else if (raz.equals(dwa)) {
29			System.out.println("due");
30		} else {
31			System.out.println("like");
32		}
33		System.out.println(raz.getClass().getCanonicalName());
34	}

Okay, now try to answer these two questions:

  1. What’s the minimal Java version needed to run this code?
  2. What will be the first line printed by this code? ene, due or maybe like?
  3. * What’s the class of the raz object?

Expect the answer (and my comment on it) soon.

The code can be also found on Github.

PS. ‘Ene, due, like, fake…' is a counting-out rhyme in Polish, quite popular I guess. You may think ‘Eeny, meeny, miny, moe…' Wikipedia.

Language selector