Is there something like User-Defined conversions in Java or any suggestion on how can I acchive same effect in java without adding tens of .toXXXX methods
I haven’t used c# for a while so I can’t remember right name for it but I also remember that in c# I was able to pass first parameter to function without using notation
Foo(MyClass instance)
but rather
instance.Foo()
If I remember correctly I had to use this keyword before MyClass something like Foo(this MyClass instance) but as I said I haven’t used c# for a while so I cant remember
Can anyone tell me what are the alternatives to this two “methods” in Java
No, there’s nothing like user-defined conversions in Java. Personally I dislike using implicit user-defined conversions in C# anyway, and rarely even write explicit ones. If the lack of them is causing you to add tens of
toXXXmethods then you should probably rethink just how widely you’d use conversions in C#.The second feature you’re talking about is extension methods which also aren’t present in Java. You just have to call static methods as normal.