6 ms·
Compared to Java 8 Kotlin still has quite a lot to offer: * Type-safe DSLs * Named parameters with default values * Non-nullable types * Raw strings (which
by oweiler 11y ago
Compared to Java 8 Kotlin still has quite a lot to offer:
* Type-safe DSLs
* Named parameters with default values
* Non-nullable types
* Raw strings (which make working with regular expressions quite nice)
* Type inference
* Properties
* Smart casts
* the when keyword which is much better than using switch statements
* data classes (very nice when working with APIs which expect Java beans)
* a lot of stuff I probably forgot
- rattray 11y agofirst-class functions is another big one
- pohl 11y agoThat was the headline feature of Java 8.
- NhanH 11y agoJava functions are still not first class. The headline feature of Java 8 was lambda function, which arguably isn't first class either (they are implemented as instances of object subtype, so essentially still is object nonetheless)
- adrusi 11y agoThey also don't close over their parent scope.
- deleted 11y ago[deleted]
- jnericks 11y ago// this hack is gross final String[] val = new String[1]; Callable func = () -> val[0] = "Hello"; func.call(); System.out.print(val[0]);
- steveklabnik 11y ago> so essentially still is object nonetheless http://www.c2.com/cgi/wiki?ClosuresAndObjectsAreEquivalent http://www.c2.com/cgi/wiki?ClosuresAndObjectsAreEquivalent
- tomjen3 11y agoKotlin can inline lambdas (sometimes), which matters a lot on Android. For example there is no over head to writing your code so that it uses map and a lambda to writing a native loop. In addition, because the code is inlined it can use the actual type of generic arguments. Not sure when that is useful.
- mike_hearn 11y agoFirst class functions mean you can define functions outside of classes. Java 8 does not have any such feature. Kotlin has quite a lot of hidden treasures in it, typically at the intersection points of several features. People who think of it as a better Java, or something Java can easily catch up with, should take a closer look.
- yareally 11y agoTechnically first class functions means functions can be treated like objects and passed around like any object (for example, python). That said, I agree with you that Java does not have first class functions. They have something tacked on that is nowhere as elegant and lacks full support. On the other hand, not every language that lets you define functions outside of classes lets you treat them like objects. C for example is generally not considered a language with true first class functions because it doesn't allow passing nested ones without additional support within the chosen complier.
- mike_hearn 11y agoAlright, in that case Kotlin has that other sense of first class functions as well. You can get a function typed object that supports the invoke operator, amongst other things.
- deleted 11y ago[deleted]