Skip to content
New issue

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

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

Already on GitHub? # to your account

Warning when using copy constructor #65

Closed
solonovamax opened this issue Oct 12, 2024 · 0 comments · Fixed by #68
Closed

Warning when using copy constructor #65

solonovamax opened this issue Oct 12, 2024 · 0 comments · Fixed by #68

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?

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

Successfully merging a pull request may close this issue.

1 participant