dotnet / java-interop

Java.Interop provides open-source bindings of Java's Java Native Interface (JNI) for use with .NET managed languages such as C#
Other
189 stars 48 forks source link

Unifying InputStream & OutputStream as System.IO.Stream causes overloaded methods/ctors failed to bind #1211

Open tuyen-vuduc opened 3 months ago

tuyen-vuduc commented 3 months ago

There was issue #494 mentioning about this, but the situation was different. I am creating a binding library where there are overloaded methods/ctors only different between Java.IO.InputStream adn Java.IO.OutputStream.

Can we map?

jpobst commented 3 months ago

Unfortunately there is no support to opt out of the Java.IO.[Input|Output]Stream -> System.IO.Stream mapping. Likewise you cannot just assign it to a random C# type like System.IO.Stream[Reader|Writer] and expect it to work.

Some things to try:

You can try using managedType on the parameter to force it to be Java.IO.InputStream, etc. But I suspect the generating plumbing code will still try to use System.IO.Stream and it probably won't compile.


For overloaded methods you might could use managedName on the method name to rename them so they are different like ProcessStreamIn () and ProcessStreamOut ().

For overloaded constructors that probably won't work. However if you aren't creating the type in C# you likely don't need both constructors.


Failing all else, you can manually write the binding code and use Java.IO.[Input|Output]Stream instead of System.IO.Stream, though that is a painful route.


Or of course if you don't actually need the methods/ctors in C# you can simply remove them.