I'm in the process of converting a program from C++ to Java. In my C++ code, I have two functions within class SomeClass that have the same name, but with different parameters, and with one function using a scope resolution operator and the other without.
SomeOtherType* SomeClass::foo()
{
//some code
}
and
SomeOtherType* foo(list<Token*>& param)
{
//some more code
}
Since Java doesn't use scope resolution operators, how do I implement these functions equivalently in Java?
Thanks in advance.
Overloading basically works the same in Java. You can define multiple methods with the same name as long as their parameters differ. So you can just write:
public SomeOtherType foo() {
return null;
}
public SomeOtherType foo(List<Token> tokens) {
return null;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With