![]() Java 8 introduced lambdas, which are built on top of a functional interface and a functional descriptor, meaning every lambda expression will map to the signature of an abstract method defined in that functional interface. Handling NULLs at compile time should result in cleaner code by removing unnecessary NULL checks in the form of an if statement, Objects.requireNonNull, Preconditions.checkNotNull, any other form. It promotes composability as in the case of the departmentName method.The Employee class has an optional department, which is good enough to conclude that every employee may not be assigned a department Optional will not protect the code from NPE, but Optional has its advantages: ![]() existingDepartments() is a function that returns an immutable list of Strings in Kotlin.Ĭlass Employee /**Įmployee needs a non-nullable "id" and an optional department to be constructed.Įmployee employee = new Employee(null, null) //NPE It would be great to see immutable collections embedded in the language, rather than relying on wrappers to generate immutable collections. Java 9 promotes immutability by introducing factory methods to create collections. These are some Kotlin features that I would love to see making a place in Java. While I have been a Java developer for quite a long while, working on the data-anonymization project made me feel that there are things that Java should consider importing from Kotlin. Kotlin is a statically typed programming language for modern multi-platform applications. ![]() However, there have been a number of languages developed on top of the JVM, like Kotlin There is no doubt that Java has enjoyed a superior position when it comes to programming languages and is considered as one of the most important languages for development.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |