I have two Java-Classes as follows:
public class MyClass {
...
}
public class MyClassList extends ArrayList<MyClass> {
...
}
Now i have any method which takes MyClassList as a parameter. The method should also accept MyClass instead. I know that I could overload the method.
Is there any possibility to achieve the same result with only one method? I am thinking of method in MyClass which automatically gets called and casts itself to MyClassList.
No. You would have to overload the method. You can’t provide user-defined implicit conversions in Java.