Skip to content

Material Slider: ACW type erasure clash when implementing OnChangeListener/OnSliderTouchListener #1482

Description

@sheiksyedm

Description

After the fix in PR #1335 (which resolved missing AddOnChangeListener/AddOnSliderTouchListener methods), implementing Slider.IOnChangeListener or Slider.IOnSliderTouchListener in a .NET Android app causes a javac build error at ACW compilation time.

Error Message

javac error JAVAC0000:
BaseOnChangeListener cannot be inherited with different arguments:
<com.google.android.material.slider.Slider>

name clash: class SliderValueChangeListener has two methods
with the same erasure, yet neither overrides the other

first method:  onValueChange(Slider, float, boolean) in BaseOnChangeListener
second method: onValueChange(Object, float, boolean) in SliderValueChangeListener

Steps to Reproduce

  1. Create a .NET Android project referencing Xamarin.Google.Android.Material (latest with PR Fixed Material Slider addOnChangeListener method missing issue #1335 fix)
  2. Implement the slider change listener:
class SliderValueChangeListener : Java.Lang.Object, Google.Android.Material.Slider.Slider.IOnChangeListener
{
    public void OnValueChange(Google.Android.Material.Slider.Slider slider, float value, bool fromUser)
    {
        // Handle value change
    }
}

// Usage
slider.AddOnChangeListener(new SliderValueChangeListener());
  1. Build the project → javac error during ACW compilation

Root Cause

The binding generates an erased OnValueChange(Object, float, bool) method on IBaseOnChangeListener (from the generic type parameter S). When the ACW creates a Java class implementing Slider.OnChangeListener (which extends BaseOnChangeListener<Slider>), Java sees two methods with the same erasure that don't override each other — causing the type clash.

The same issue affects BaseOnSliderTouchListener with OnStartTrackingTouch/OnStopTrackingTouch.

Expected Behavior

Implementing Slider.IOnChangeListener or Slider.IOnSliderTouchListener should compile and work without any javac errors.

Environment

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions