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

Using validate(this) in init occurs error when it comes to open / abstract class #69

Open
JayAhn2 opened this issue Aug 30, 2021 · 1 comment

Comments

@JayAhn2
Copy link

JayAhn2 commented Aug 30, 2021

Expected Behavior

Probably this report is due to my lack of proficiency in Kotlin. I want to validate values of a constructor in abstract or open class. If there is no way to achieve it as below. Please guide me how to do the same thing.

abstract class Quantity(open val value: Int) : BaseValueObject() {
    init {
        validate(this) {
            validate(Quantity::value).hasDigits()
        }
    }
}

Actual Behavior

image

Steps to Reproduce the Problem

  1. Write abstract class as above

Example Code or Link to a Project

As above

Environment

  • Valiktor version: 0.12.0
  • JDK/JRE version: Open JDK 11
  • Platform/OS: Mac
@PierrickPuimeanChieze
Copy link

Yeah, logical here. Reason given here : https://stackoverflow.com/questions/9851813/java-leaking-this-in-constructor/9851843#9851843. Nothing valiktor could correct.

One suggestion, maybe : write a method instead, for example executeValidation(), and call this method from constructor or whatever in the child classes. This is the approach I elected to follow.

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

No branches or pull requests

2 participants