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

Warning when using copy constructor #65

Open
solonovamax opened this issue Oct 12, 2024 · 0 comments
Open

Warning when using copy constructor #65

solonovamax opened this issue Oct 12, 2024 · 0 comments

Comments

@solonovamax
Copy link

solonovamax commented Oct 12, 2024

As RGB, and (I believe) all other implementations of Color are all data classes, they expose a copy constructor. I personally find this extremely convenient & useful for modifying a single component of a colour, instead of having to use map.

For example:

color.copy(alpha = 0.0f)
color.copy(alpha = color.alpha * glowOpacity)

However, in recent versions of kotlin, the following warning is emitted:

w: This 'copy()' exposes the non-public primary constructor of a 'data class'. Please migrate the usage. See the appropriate 'data class' documentation or contact the 'data class' author for migration guidance. This will become an error in Kotlin 2.1.

this is due to the constructor being marked as internal.

would it be possible to methods that do the same thing as copy, allowing you to create a new instance of the colour, changing some fields?

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

No branches or pull requests

1 participant