![]() To be explicit, Java 8 introduced the Optional type. In Java, there's no way to know whether a variable is null. You still need to add the static keyword, which nearly nobody uses. More importantly, it doesn't offer its immutable counterpart, val. ![]() First, it's only available for local variables. Plus, one cannot reassign method parameters. Kotlin doesn't leave you a choice: every property and local variable needs to be defined as either a val or a var. Most Java code doesn't take advantage of immutable references. While Java allows you to define immutable references, it's not mandatory. For example, Spring's GenericBean uses immutable attributes, but neither immutable method parameters nor local variables slf4j's DefaultLoggingEventBuilder uses none of the three. Interestingly, using the final keyword is not widespread, even in widely used projects. Immutable references are a great help in avoiding nasty bugs. Enter fullscreen mode Exit fullscreen mode
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |