I'm implementing a customized Parcelable interface using Kotlin (Original Android's API: https://developer.android.com/reference/kotlin/android/os/Parcelable). How can I enforce a static field (i.e. companion object) similar to how the CREATOR field is enforced?
Asked
Active
Viewed 134 times
0
-
Does this answer your questions: https://stackoverflow.com/questions/35327443/companion-objects-in-kotlin-interfaces ? – lukas.j Jul 05 '22 at 07:46
-
I don't think so. The code in the answer doesn't "enforce" the subclasses to implement the CREATOR. For example, if I implement that interface without CREATOR val, no error will be raised – Đặng Minh Hiếu Jul 05 '22 at 07:56
-
I think it answers your question: it can't. – lukas.j Jul 05 '22 at 07:58
-
Then is there a way to work around that? And how did Android library manage to raise an error when I don't implement CREATOR field, assuming it can't implement such enforcements? – Đặng Minh Hiếu Jul 05 '22 at 08:03