4 ms·
Slightly off-topic, but does Java have standalone (without a class) functions now? He said he was using Java but I didn't recognize some of this syntax. I know
by _bxg1 7y ago
Slightly off-topic, but does Java have standalone (without a class) functions now? He said he was using Java but I didn't recognize some of this syntax. I know it's been changing a lot the past few years (and it's been a few years since I've used it).
- dodobirdlord 7y agoSort of yes but not really. Java has a concept now of a Functional Interface, an interface that has only one abstract method. Classes that implement a functional interface can be treated in a lot of ways like functions, and there is syntactic sugar that amounts to inferring that an object can be treated as a function by calling its only method if it is known in the scope as an interface type with only one method. There's also syntactic sugar for a concept called "lambdas", by which one can inline declare anonymous classes with only one method by just defining the method.
- quelltext 7y agoNope. I think he simply used that notation to keep things simple/concise and focus on the important pieces.
- _bxg1 7y agoThat's what I was wondering. Odd decision in a post that works through code line by line and then translates it straight to bytecode.