Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constructor argument Polymorthism #176

Closed
punksta opened this issue May 24, 2017 · 5 comments
Closed

constructor argument Polymorthism #176

punksta opened this issue May 24, 2017 · 5 comments
Assignees
Labels
Milestone

Comments

@punksta
Copy link

punksta commented May 24, 2017

sealed class Param : Parcelable
abstract class ParamA : Param()
abstract class ParamB : Param()

sealed class Holder<out T: Param>(val param: T): Parcelable

@PaperParcel
class HolderA(paramA: ParamA) : Holder<ParamA>(paramA), PaperParcelable {
    companion object {
        @JvmField val CREATOR = PaperParcelHolderA.CREATOR
    }
}

@PaperParcel
class HolderB(paramB: ParamB) : Holder<ParamB>(paramB), PaperParcelable {
    companion object {
        @JvmField val CREATOR = PaperParcelHolderB.CREATOR
    }
}

does not work:

error: No field match found for the constructor parameter "paramB" in solutions.coub.com.flowers.model.payments.HolderB. Constructor arguments are matched with fields via their name and type.

if rename paramB and paramA into param Creator of HolderA and B will use type Param for their's constructor argument.

Is it possible to check generic value of current class to find class of constructor argument?

@grandstaish
Copy link
Owner

Oops, yeah that should be possible to fix. I'll try have a fix and a new release in the weekend!

@grandstaish grandstaish self-assigned this May 24, 2017
@grandstaish grandstaish added this to the 2.0.2 milestone May 24, 2017
@grandstaish
Copy link
Owner

I just pushed a snapshot if you want to try it out straight away. Just add the snapshot repo and deps:

repositories {
    maven { url "https://oss.jfrog.org/artifactory/oss-snapshot-local/" }
}

dependencies {
    compile 'nz.bradcampbell:paperparcel:2.0.2-SNAPSHOT'
    compile 'nz.bradcampbell:paperparcel-kotlin:2.0.2-SNAPSHOT'
    kapt 'nz.bradcampbell:paperparcel-compiler:2.0.2-SNAPSHOT'
}

The working code:

sealed class Param : Parcelable
abstract class ParamA : Param()
abstract class ParamB : Param()

sealed class Holder<out T: Param>(val param: T): PaperParcelable

@PaperParcel
class HolderA(param: ParamA) : Holder<ParamA>(param) {
  companion object {
    @JvmField val CREATOR = PaperParcelHolderA.CREATOR
  }
}

@PaperParcel
class HolderB(param: ParamB) : Holder<ParamB>(param) {
  companion object {
    @JvmField val CREATOR = PaperParcelHolderB.CREATOR
  }
}

Note: I moved PaperParcelable to the Holder class. Not required, I just like this style more.

@punksta
Copy link
Author

punksta commented May 24, 2017

@grandstaish Cool, I will check it at the end of day. Thanks for fast reply.

@punksta
Copy link
Author

punksta commented May 27, 2017

snapshot works, thanks.

@grandstaish
Copy link
Owner

Fyi, 2.0.2 has just been released with this fix included. Sorry about taking so long!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants