Sometimes, we need to create an object of a class that slightly changes a class without explicitly declaring a new subclass for it. Java handles this situation with anonymous inner classes . Kotlin briefly summarizes this concept with object expressions and object declarations .
in JAVA:
DataBindingUtils.addCallBack(this, mActivityVM.goToSimple, new Observable.OnPropertyChangedCallback() { @Override public void onPropertyChanged(Observable observable, int i) { goToBase (); } });
in Kotlin:
DataBindingUtils.addCallBack ( this, mainActivityVM? .goToSimple, object : Observable.OnPropertyChangedCallback() { override fun onPropertyChanged(p0: Observable?, p1: Int) { } })
Use object to process, if you use java to process anonymous inner classes, an error will be reported