Skip to content

Default Instance Java Interface Methods are ignored by Binding Tools #7125

@jedusei

Description

@jedusei

Android application type

Classic Xamarin.Android (MonoAndroid12.0, etc.)

Affected platform version

VS 2022 17.2.4

Description

The binding tools seem to ignore default instance interface methods when generating the C# interface.

For example, for the following Java interface:

package com.example.calculator;
public interface Calculator {
    default int Add(int a, int b) {
        return a + b;
    }
    
    int Subtract(int a, int b);
}

This is the C# interface that is generated:

public interface ICalculator {
    int Subtract(int a, int b);
}

Steps to Reproduce

  1. Create a new file: Calculator.java
  2. Paste the Java interface code written in the description into the file.
  3. Open a terminal in the folder containing Calculator.java
  4. Run javac Calculator.java && jar -cf Calculator.jar Calculator.class. You should see a Calculator.jar file afterwards.
  5. Create a new Android Binding Project and add Calculator.jar to it.
  6. Build the project.
  7. Open the Object Browser (View > Object Browser), click the dropdown at the top of the window, and click My Solution.
  8. Find the binding project in the list and find the ICalculator interface in the Com.Example.Calculator namespace, right-click on it and click Go To Definition.
  9. The interface code will show up, and you'll see that even though there's a Subtract method, no Add method was generated.

Did you find any workaround?

I encountered the issue while creating a binding for the Twilio Conversations Android SDK. The only workaround I could come up with was to manually write the interface method & its invoker implementation.

Relevant log output

No response

Metadata

Metadata

Assignees

Labels

Area: BindingsIssues in Java Library Binding projects.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions