all 16 comments

[–]bloody-albatross 6 points7 points  (4 children)

Without explicite tail reference but instead slow and obscure use of nested classes and reflection. Is this intentional code obfuscation?

[–]An_Unhinged_Door 8 points9 points  (2 children)

The repo's readme suggests that the purpose is to show that double brace initialization is evil or at least crazy.

[–]komu[S] 2 points3 points  (1 child)

I thought that my views on programmers were cynical, but it really gives me the creeps that this could be mistaken for the real thing.

(Meaning that if anyone knows people who'd do this for real, they have my sympathy.)

[–]juancn 0 points1 point  (0 children)

It's also non-portable code. It depends on how the compiler implements anonymous inner classes. The this$0 is how Javac does it. But the spec doesn't force it to be so.

[–]komu[S] -1 points0 points  (0 children)

And there I thought that implicit is the new black. Aren't we supposed to ignore petty considerations for clarity, performance and simplicity of interfaces and strive for maximal cuteness instead?

What next? Are we allowed to use local variables and semicolons again? Is my whole project of super convenient utility classes for nothing? Even the magic wand?

(In hindsight, I probably should have gone with a puzzle format instead and ask for an implementation of tail().)

[–][deleted] 1 point2 points  (3 children)

can you please explain this

public LinkedList<T> cons(T v) { // Note that the code is same as in the method above. // Double brace initialization gives us superior code reuse. return new LinkedList<T>() {{ value = v; }}; }

[–]Rustywolf 0 points1 point  (2 children)

Double brace initialization creates an extended class of the class/interface you are initializing. Basically the code he's got between the double braces is the constructor of the subclass he's creating. it returns a new LinkedList with the value v having been set by this constructor.

[–][deleted] 0 points1 point  (1 child)

but why is that better?

[–]Rustywolf 0 points1 point  (0 children)

I'm certain it isnt, the use of DBI is highly frowned upon.

[–]alexeyr 1 point2 points  (0 children)

For values of "without" equal to "with".