Summary of points I was worried about when migrating from java to kotlin

Just list the stumbling points when trying to replace the code of an Android application written in Java with kotlin

Development environment IDE : android studio OS : mac

What I misunderstood

--If you use kotlin, nullpo will not occur

1. I got angry when I tried to use HashMap as it is

The following Java code may be used Map seems to be read-only in kotlin Therefore, a mutableMap that can be changed is used instead.

Map map = HashMap<>

It's revealed that I didn't write it as read-only until now.


MutableMap map = HashMap<>

2. Strict null check

It makes me angry every time there is code that seems to contain null So I tried to do a null check just before that code

However, there is an Elvis operator that throws an exception when the value is null. It seems that it was possible to prevent the amount of writing if statements from increasing.


val hoge = func()


func()?.fuga() ?: throw Exception("Akan") 

?. is a safe call It seems to return null if the previous expression was null

Recommended Posts

Summary of points I was worried about when migrating from java to kotlin
What I thought about when I started migrating from Java to Kotlin
Summary of good points and precautions when converting Java Android application to Kotlin
Precautions when migrating from VB6.0 to JAVA
Summary of moss when updating from JMockit 1.4 to 1.30
What I did when I converted java to Kotlin
[Java Silver] Summary of points related to lambda expressions
I tried to summarize the basics of kotlin and java
How to write and notes when migrating from VB to JAVA
ClassCastException occurs when migrating from Java7 to Java8 ~ Generics and overload ~
Notes on building Kotlin development environment and migrating from Java to Kotlin
What I was addicted to when updating the PHP version of the development environment (Docker) from 7.2.11 to 7.4.x
Since I switched from Spring Boot (Java) to Ruby on Rails, I summarized my favorite points of Rails.
[Java Silver] Summary of access modifier points
What I don't like when using interface of a function with default arguments in Kotlin from Java
I was addicted to a simple test of Jedis (Java-> Redis library)
[java] Summary of how to handle char
Changes when migrating from Spring Boot 1.5 to Spring Boot 2.0
[Java] [Maven3] Summary of how to use Maven3
Changes when migrating from Spring Boot 2.0 to Spring Boot 2.2
I translated the grammar of R and Java [Updated from time to time]
Memo for migration from java to kotlin
[Updating] It was difficult to upgrade from httpclient 3.x series to 4.5, so I will write a summary of changes
[Promotion of Ruby comprehension (1)] When switching from Java to Ruby, first understand the difference.
Points I stumbled upon when creating an Android application [Updated from time to time]
Run R from Java I want to run rJava
Summary of what I learned about Spring Boot
Things to be aware of when writing Java
[Java] Summary of how to abbreviate lambda expressions
Migrate from Java to Server Side Kotlin + Spring-boot
Points to worry about when handling variables personally
I want to write quickly from java to sqlite
[Elasticsearch × Java] Since the execution result of the query acquired in Java was different from the assumption, I investigated → Summary of the corresponding contents
When I tried to unit test with IntelliJ, I was told "java.lang.OutOfMemoryError: Java heap space"
The part I was addicted to in "Introduction to Ajax in Java Web Applications" of NetBeans
Summary of how to use the proxy set in IE when connecting with Java
Today's learning that I was worried about DB design
[Java] I want to calculate the difference from the date
How to write Scala from the perspective of Java
I was addicted to the record of the associated model
Behavior when calling Java variadic methods from Scala / Kotlin / Java
The story of migrating from Paperclip to Active Storage
Java language from the perspective of Kotlin and C #
6 features I missed after returning to Java from Scala
Summary of knowledge required to pass Java SE8 Silver
GetXxxx of ResultSet was addicted to primitive type (Java)
Summary of Java communication API (1) How to use Socket
[Eclipse] Summary of environment settings * Updated from time to time
I want to transition screens with kotlin and java!
Summary of Java communication API (3) How to use SocketChannel
Summary of Java communication API (2) How to use HttpUrlConnection
Summary of how to implement default arguments in Java
[Java] Things to be aware of when outputting FizzBuzz
A summary of what Java programmers find when reading Kotlin source for the first time
How to batch initialize arrays in Java that I didn't know when I was a beginner
Changes from Java 8 to Java 11
Sum from Java_1 to 100
Technical causes and countermeasures for the points that I was addicted to with the Android app & Kotlin (2. Processing related to the camera function of Android *)
From Java to Ruby !!
About Java entry points
Personal summary about Java