赞
踩
//Java
public class Utils {
private Utils() {
}
public static int getScore(int value) {
return 2 * value;
}
}
//Kotlin
class Utils private constructor() {
companion object {
fun getScore(value: Int): Int {
return 2 * value
}
}
}
// 或者
object Utils {
fun getScore(value: Int): Int {
return 2 * value
}
}
//Java
public class Developer {
private String name;
private int age;
public Developer(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
//kotlin
data class Developer(val name: String, val age: Int)
//Java
final int andResult = a & b;
final int orResult = a | b;
final int xorResult = a ^ b;
final int rightShift = a >> 2;
final int leftShift = a << 2;
final int unsignedRightShift = a >>> 2;
//kotlin
val andResult = a and b
val orResult = a or b
val xorResult = a xor b
val rightShift = a shr 2
val leftShift = a shl 2
val unsignedRightShift = a ushr 2
//Java
String text = "First Line\n" +
"Second Line\n" +
"Third Line";
//kotlin
val text = """
|First Line
|Second Line
|Third Line
""".trimMargin()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。