0

I have a Java pojo class like this:

public class Event {
    private final List<String> urls;
    private final int totalPhotoCount;
    private final Owner owner;

    public Event(@NonNull List<String> photoUrls,
                 int totalPhotoCount,
                 @Nullable Owner owner) {
        urls = photoUrls;
        this.totalPhotoCount = totalPhotoCount;
        this.owner = owner;
    }


    @NonNull
    public List<String> getUrls() {
        return urls;
    }

    public int getTotalPhotoCount() {
        return totalPhotoCount;
    }

    @Nullable
    public Owner getOwner() {
        return owner;
    }
}

now I need to extend this class in a kotlin data class and add extra field - let's say String data. How can I achieve it? I cannot convert that class to kotlin

2
  • Kotlin just can't read a Java class, he just can read bytecode. so, I think you need first to transform this class into .class file. Commented Mar 17, 2020 at 14:56
  • You have an option to convert java to kotlin (when you right clic on your file in Android Studio) (see kotlinlang.org/docs/tutorials/mixing-java-kotlin-intellij.html) Commented Mar 17, 2020 at 14:57

1 Answer 1

1

Create a .kt file and add the class like this:

data class EventSubclass(
        private val data: String,
        private val photoUrls: List<String>,
        private val totalPhoto: Int,
        private val mOwner: Owner
) : Event(photoUrls, totalPhoto, mOwner) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.