What are Object expressions i...
What are Object expressions i...
In Kotlin, an object expression is a way to create an anonymous class instance on the fly. It is used when you need to create an object of a class with some modifications or additional functionality, without defining a separate class for it.
Implementing an interface with some additional logic: You can create an object expression that implements an interface and provides its own implementation for the interface methods.
Extending an existing class with some modifications: You can create an object expression that extends an existing class and overrides or adds new properties and methods.
Creating a singleton-like object: Although Kotlin has a dedicated keyword for creating singletons (object declarations), you can use object expressions to create a singleton-like object with some additional logic or properties.
Passing a function as an argument: You can use object expressions to create an instance of a class that implements a functional interface or a SAM (Single Abstract Method) interface, which is often used when passing a function as an argument to another function.
int...
senior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào