w Javie, instancję obiekt interfejs jest tak proste, jak new Interface()
... i zastąpić wszystkie wymagane funkcje, jak poniżej, na AnimationListener
Jak instancję anonimową klasy, która implementuje interfejs w Kotlin
private void doingSomething(Context context) {
Animation animation = AnimationUtils.loadAnimation(context, android.R.anim.fade_in);
animation.setAnimationListener(new Animation.AnimationListener() {
// All the other override functions
});
}
jednak w języku Kotlin, gdy wpisujemy:
private fun doingSomething(context: Context) {
val animation = AnimationUtils.loadAnimation(context, android.R.anim.fade_in)
animation.setAnimationListener(Animation.AnimationListener(){
// All the other override functions
})
}
Nie można rozpoznać reklamacji dotyczących błędów Referencje AnimationListener.
Możliwy duplikat [Jak utworzyć instancję anonimowego interfejsu w Kotlin?] (Http://stackoverflow.com/questions/37672023/how-to-create-an-instance-of-anonymous-interface -in-kotlin) – miensol