I have the following code in Java which I want to convert to Kotlin:
class RideHistoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
class HistoryItemHolder extends RecyclerView.ViewHolder {
private static final int TYPE_IN_PROGRESS = 1
private static final int TYPE_CANCELLED = 2
private static final int TYPE_FINISHED = 3
// class methods and properties are written
}
}
I have come up with the following code:
class RideHistoryAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private inner class HistoryItemHolder(view: View)
: RecyclerView.ViewHolder(view) {
private companion object {
private const val TYPE_IN_PROGRESS = 1
private const val TYPE_CANCELLED = 2
private const val TYPE_FINISHED = 3
// class methods and properties are written
}
}
}
Android Studio is showing a red squiggly under "object" of the line companion object
, saying:
Companion object is not allowed here
Note: I know I can convert it to non-inner class but I'd prefer keeping it one. I also checked I can't define an interface in an inner class too.