I want to convert my java project to Kotlin, there are more than 500 java files. How can I convert it into Kotlin easily?

I know that we can convert one by one java file to Kotlin, But there are many files.

我能马上转换吗?

推荐答案

你绝对可以试试.您只需在Project navigator中 Select 一个模块或文件夹,然后 Select Code --> Convert Java file to Kotlin file:

Convert complete module to Kotlin

You, though, need to keep in mind that the conversion is not perfect. For instance, Android Studio will have to guess whether a whole lot of properties are nullable or not. It will not get them all right... you will get a lot of crashes.

My suggestion would be to batch files in sensible chunks, so you can fix those Kotlinized files without getting swamped with errors.

Note: after converting a file to Kotlin you still will need to review it. A lot of things will be kept in Java for the sake of safety, but now that you have Kotlin you can use collection extensions, default constructor parameters, ...

Kotlin相关问答推荐

Jetpack Compose中的数字 Select 器问题

用普通Kotlin理解Gradle的Kotlin DSL'""

如何在Jetpack Compose中从领域查询中读取数据?

在Kotlin中求n个ClosedRange实例相交的最常用方法是什么?

Android Studio中的只读集合不支持操作失败的原因是什么?

同时也是一个字符串的 Kotlin 枚举

TzdbZoneRulesProvider 在 java.time 中不工作

将一个列表元素分组为多个组(indexBy)

gradle 如何 Select 以-jvm结尾的库?

为什么在 Kotlin 中调用私有构造函数会导致错误为无法访问 是什么?

Koin Android:org.koin.error.NoBeanDefFoundException

无法删除部分子项.这可能是因为进程打开了文件或将其工作目录设置在目标目录中

如何禁用智能投射突出显示 Kotlin?

Gradle 同步失败:不支持的方法:KotlinPlatformContainer.supports()

Kotlin - mutableMapOf() 会保留我输入的顺序

main函数和常规函数有什么区别?

如何在Kotlin中创建填充空值的通用数组?

将ExpectedException与Kotlin一起使用

Kotlin扩展函数与成员函数?

Android Kotlin .visibility