java转换成kotlin语言教程_#7 Kotlin教程 | 把Java转换为Kotlin

欢迎大家回来

So welcome back Aliens.

上个视频我们讲了如何把 Java 代码和 Kotlin 代码结合起来

In the last video we have talked about how can you mix Java and Kotlin together.

不过我还有一个小技巧 而且我在以前的课程中用到过

But there’s one trick there. So since I have done that before in my session.

它也确实起作用了 不过对于第一次使用这个技巧

It was working. It may happen that if you’re doing this for the first time.

你必须将

You have to add

Kotlin 的支持包或者 Java 的支持包 呃……

the Kotlin support for your project or maybe Java support for your…

就是 Kotlin 的支持包添加到你的项目中

I mean the Kotlin support for your project.

那么

So in fact

这里我已经创建好了 Kotlin 的项目 对吧?

I will…I’ll have created the Kotlin project, right?

为了防止你遇到什么报错问题

But then in case if you’re getting some error.

一旦你创建好你的 Kotlin 文件

Once you create your Kotlin file,

然后又遇到了报错 那这里有个可选设置

if you get an error, there will be an optional configure here.

是的 就在上面这

Ok. So on the top of this.

这里会有一个可选设置

There will be optional configure.

你只需要点开设置 然后全选所有模块

You just have to configure it and you will have to select all modules.

它会给你三个选项 你就全选所有模块 然后点击 OK 就可以了

It will give you to three options. Out of that, you have to select all modules and click OK.

一切就会正常了

Everything would be fine.

当然如果你碰到了其他什么问题 请在评论区告诉我

I guess if you’re getting some issues, let me know in the comment section if you are

比如你在设置的时候遇到了什么问题的话

getting the problem to configure that.

接下来我还要给你们看另一个 InteliJ 中的技巧

But then we have one more trick in InteliJ which I want to show you here.

这是我们的类 Alien 这是我们用 Java 代码写的类

So this class which is Alien. This is a class where you have. This is Java code.

比如说

So let’s say

你已经写好了 Java 代码 但之后

we have done the Java code. And later you want a

你想要把它写成 Kotlin 那我们能把 Java 代码转写成 Kotlin 代码吗?那当然可以

Kotlin code of this. Can you convert a Java code into Kotlin? I mean we can.

程序员都可以

As…… as programmers can.

但 InteliJ 是可以直接转换的

InteliJ can convert that. It’s actually possible.

好 那就直接选择你的类 然后选择这里的 Code 菜单

So just select your class and go to the Code menu there.

在下面这里 你可以找到一个选项

You can see down down here. We got an option which is convert

用来转换 Java 文件成为 Kotlin 文件 让我们来试试 先点击它

Java file to Kotlin file. And let’s try this. If you click on this…

我觉得我这里没什么问题 点击后 你们看这里 看到了吗?

I would say OK. I don’t have any problem with that. And the moment you do that, can you see that?

代码变了 你得到了一个叫做 Alien 的类

It is change. You got a class called Alien.

类中有一个 name 变量 类型是 String 默认的值是空值 null

And they got a variable name which is type String and the default value is null.

这已经是 Kotlin 代码了

And this is a Kotlin code now.

然后你的类这里名字也变成了

And this is your class which is also

Alien.kt 了 Java代码就没了

Alien.kt now. There is no more

全变成 Kotlin 代码了

Java code. This is a Kotlin code.

你可以写一堆大型 Java 代码 然后都给转换成 Kotlin

So you can write a big code and you can convert that code into Kotlin.

就是这么有效率 这也是为什么我这么喜欢

It’s that efficient. And that’s why I love to use

用 InteliJ 这个平台的原因 好的 技巧就是这样 下一个视频我们要多讲

InteliJ platform. So yeah. That’s just this one. In the next video we’ll talk about

几个问题 看到这里的你们就点个订阅吧

more topics. So before that, do subscribe and

把这个视频分享给你们的朋友 希望你们都喜欢

share this video to your friends if you like this video.

如果有什么意见建议

And do let me know your

一定告诉我 今天就到这里 我是 Klan 感谢收看

feedback on this video. That’s the time. Thanks watching and this is Klan.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值