12

My Java project has an ItemType interface with the given values, which is implement by some classes. How can I implement this interface on Kotlin?

public interface ItemType { int TYPE_OPTION = 2; int TYPE_GRID = 3; int TYPE_CAROUSEL = 4; int TYPE_MUSIC = 5; int TYPE_GUESS = 6; int getItemType(); } 
1
  • 1
    Wouldn't this be better as an enum? Commented Aug 1, 2019 at 20:44

1 Answer 1

15

You can use the companion object:

interface ItemType { val itemType: Int companion object { const val TYPE_OPTION = 2 const val TYPE_GRID = 3 const val TYPE_CAROUSEL = 4 const val TYPE_MUSIC = 5 const val TYPE_GUESS = 6 } } 
Sign up to request clarification or add additional context in comments.

1 Comment

It would be better if you put the reason why an issue occurs and how the solution works.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.