10/31/2023 0 Comments Java to kotlin![]() ![]() One of them is package scope - or, to be exact, the lack of such! If you don't think it's a big deal, see Jakub Nabrdalik's presentation - Keep IT clean: mid-sized building blocks and hexagonal architecture. Lukasz: I feel like it's time to dive into the disadvantages of Kotlin. You can also substitute Java's Supplier, Consumer, and other interfaces for a simple and more intuitive () -> You can declare functions outside of an object or classes. Lukasz: Precisely! I'd also say that Kotlin uses syntax that makes applying HOF (a higher-order function) easy. The code we end up with is neat and easy to reason about. This leads us to a custom extension to the Query class, which you can see in the (5) line. We also want to be able to chain our include() calls. We then want the third-party Query class from the MongoDB driver to skip them. Methods in lines (3) and (4) can produce empty Criteria. If either value is empty, we want to skip the corresponding condition. ![]() The filter() method then extends any database query to include min and max year conditions. If you look at lines (1) and (2), the class has two optional integer fields. ![]() We have recently implemented a mechanism for list filtering this way. Such a solution helps prevent potential errors when the given value becomes null and we try to recall its method. The programming language uses the safe navigation operator (?.) or optional chaining, as TypeScript developers tend to call it. Krzysiek: I've also noticed that Kotlin takes null safety more seriously. While migrating a class from Java to Kotlin - which is one of the functions of IntelliJ IDEA - I suddenly realized that the NullPointerException (NPE) lurks around every corner. Lukasz: The syntax of Kotlin clearly shows that Java code is susceptible to nulls. Magdalena: Speaking of seamless integration, IntelliJ IDEA even suggests changing the language when you copy Java code to Kotlin class. This makes it simple to rapidly introduce the language into a project as you can use familiar toolkits. Other Java frameworks such as Micronaut also try to support Kotlin. Lukasz: Kotlin works well with the Spring Framework - there's virtually no difference between Java and Kotlin here. ![]() How Kotlin Works With Frameworks and Tools ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |