刚学习Kotlin,知道怎么在Kotlin中使用java的东西,java里面怎么用Kotlin不太清楚,那个高手给示范一下.
http://blog.csdn.net/zouchengxufei/article/details/50555133
1楼发的链接是kotlin文件,不是java啊
你的意思是在用java 打开kotlin吗? 那是不可能的呀,你学kotlin应该有教要先导一个kotlin的库类,然后才能进行kotlin的编译啊,
只是现在的Studio提供了一个java文件转换为kotlin文件的功能,但是这一个过程是不可逆的
3楼,我是想知道java中怎么使用kotlin文件中定义的对象,应该可以吧,网上都有例子,不过没有说明怎么把kotlin文件引入进去的.
比如;
kotlin代码
data class Student(val name:String,val sex:Char,val age:Int,val course:Array){
}
1
2
3
1
2
3
java调用代码
public void demo() {
Student[] students = new Student[]{
new Student("x1",'男',14,new String[]{"数学","语文"}),
new Student("x2",'女',15,new String[]{"英语","语文"}),
new Student("x3",'男',16,new String[]{"化学","语文"}),
new Student("x4",'女',17,new String[]{"物理","语文"}),
};
for (Student student : students) {
Log.v(TAG,student.toString());
}
}
引用http://blog.csdn.net/u012296101/article/details/50986082
没有说明Student怎么引用的,文件不全.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
/**
java 调用kotlin
/
public class javaActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startActivity(new Intent(this,kotlinActivity.class));
}
}
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.and.myapplication.thor.start
/**
super.onCreate(savedInstanceState)
startActivity(Intent(this,javaActivity::class.java))
}