Kotlin Language Documentation 1.3@JvmDefault annotation. Here is an example of a Kotlin interface with a default method: interface Robot { @JvmDefault fun move() { println("~walking~") } fun speak(): Unit } The default implementation implementing the interface. //Java implementation public class C3PO implements Robot { // move() implementation from Robot is available implicitly @Override public void speak() { System implementation from the Robot interface c3po.speak(); Implementations of the interface can override default methods. Default methods in interfaces 362 //Java public class BB8 implements Robot { //own implementation0 码力 | 597 页 | 3.61 MB | 1 年前3
Kotlin Language Documentation 1.9.20example of a Kotlin interface with a default method: // compile with -Xjvm-default=all interface Robot { fun move() { println("~walking~") } // will be default in the Java interface fun speak(): implementing the interface. //Java implementation public class C3PO implements Robot { // move() implementation from Robot is available implicitly @Override public void speak() { System default implementation from the Robot interface c3po.speak(); Implementations of the interface can override default methods. //Java public class BB8 implements Robot { //own implementation of the0 码力 | 1299 页 | 32.44 MB | 1 年前3
Kotlin 1.9.10 官方文档 中文版
interface Robot { fun move() { println("~walking~") } // will be default in the Java interface fun speak(): Unit } 默认实现对于实现该接口的 Java 类都可用。 //Java 实现 public class C3PO implements Robot { // 来自 Robot 的 move() 实现隐式可用 @Override public void speak() { System.out.println("I beg your pardon, sir"); } } C3PO c3po = new C3PO(); c3po.move(); // 来自 Robot 接口的默认实现 c3po c3po.speak(); 接口的实现者可以覆盖默认方法。 //Java public class BB8 implements Robot { //自己实现默认方法 @Override public void move() { System.out.println("~rolling~"); } @Override public0 码力 | 3753 页 | 29.69 MB | 1 年前3
Kotlin 官方文档中文版 v1.9interface Robot { fun move() { println("~walking~") } // will be default in the Java interface fun speak(): Unit } 默认实现对于实现该接口的 Java 类都可用。 //Java 实现 public class C3PO implements Robot { // 来自 Robot 的 move() 实现隐式可用 @Override public void speak() { System.out.println("I beg your pardon, sir"); } } C3PO c3po = new C3PO(); c3po.move(); // 来自 Robot 接口的默认实现 c3po c3po.speak(); 接口的实现者可以覆盖默认方法。 //Java 在 Java 中调用 Kotlin 926 public class BB8 implements Robot { //自己实现默认方法 @Override public void move() { System.out.println("~rolling~");0 码力 | 2049 页 | 45.06 MB | 1 年前3
Hello 算法 1.1.0 Kotlin版ger2、theNefelibatas、yuelinxin、xiongsp、nanlei、a16su、 cy‑by‑side、gaofer、malone6、Wonderdch、hongyun‑robot、XiaChuerwu、yd‑j、bluebean‑cloud、 iron‑irax、he‑weilai、Nigh、MolDuM、Phoenix0415、XC‑Zero、SamJin98、reeswell、NI‑SW、0 码力 | 381 页 | 18.47 MB | 1 年前3
Hello 算法 1.2.0 简体中文 Kotlin 版magentaqin、Wonderdch、 malone6、xiaomiusa87、gaofer、bluebean‑cloud、a16su、Shyam‑Chen、nanlei、hongyun‑robot、 Phoenix0415、MolDuM、Nigh、he‑weilai、junminhong、mgisr、iron‑irax、yd‑j、XiaChuerwu、XC‑ Zero、seven1240 码力 | 382 页 | 18.48 MB | 10 月前3
Hello 算法 1.2.0 繁体中文 Kotlin 版magentaqin、Wonderdch、 malone6、xiaomiusa87、gaofer、bluebean‑cloud、a16su、Shyam‑Chen、nanlei、hongyun‑robot、 Phoenix0415、MolDuM、Nigh、he‑weilai、junminhong、mgisr、iron‑irax、yd‑j、XiaChuerwu、XC‑ Zero、seven1240 码力 | 382 页 | 18.79 MB | 10 月前3
共 7 条
- 1













