burhanrashid52 / PhotoEditor

A Photo Editor library with simple, easy support for image editing using paints,text,filters,emoji and Sticker like stories.
MIT License
4.14k stars 991 forks source link

Fix Builder methods' return type in Java #518

Closed unbiaseduser closed 1 year ago

unbiaseduser commented 1 year ago

I noticed that SaveSetting.Builder's method properly return itself in Kotlin but return void in Java instead. I figured out the issue. When you define a mutable property in Kotlin, the compiler automatically generates a getter and setter method for it under the hood. It happens that the implicitly generated setter has the same name as the correct setter, so the correct setter gets "overwritten". Let's take the isTransparencyEnabled property as an example. Since it is a mutable property (var), getter and setter methods are automatically generated (isTransparencyEnabled() as getter and setTransparencyEnabled() as setter). Since the Builder already has a setTransparencyEnabled() method (which returns the builder), the property's generated setTransparencyEnabled() method (which returns void) overwrites the Builder returning method. The least disruptive solution I can think of is to mark the Builder's field as @JvmField to still allow Kotlin callers to access the properties (for whatever reason), while fixing the issue for Java callers.