Skip to content

Instantly share code, notes, and snippets.

@AdamMc331
Created March 18, 2019 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamMc331/2f391dfc023d935fc02e928a09a1f208 to your computer and use it in GitHub Desktop.
Save AdamMc331/2f391dfc023d935fc02e928a09a1f208 to your computer and use it in GitHub Desktop.
// In Java, I can do this
public class MainClass {
interface MyInterface {
public void printName();
}
}
public class SubClass extends MainClass {
}
// Notice here that I use `SubClass.MyInterface` so the client doesn't know MainClass exists.
public void handleInterface(SubClass.MyInterface implementation) {
}
// In Kotlin, I cannot do this
open class MainClass {
interface MyInterface {
fun printName()
}
}
class SubClass : MainClass()
// This will not compile unless I do `MainClass.MyInterface`. See the Java notes about why I might want that.
fun handleInterface(implementation: SubClass.MyInterface) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment