Answer the question
In order to leave comments, you need to log in
How to give functions multiple names in Kotlin?
I have a function that is used in different contexts and it would be convenient for me to call a function with a name defined for this context from each context. Is this possible without copying the code?
Answer the question
In order to leave comments, you need to log in
A function should only do one thing. If the function performs 2 actions, then the function is broken.
If you have an abstract function that works with generics, then you need to give it a generic name.
For example, you can call the function
openFile(path: String) - which opens only files or ..
openAtPath(path: String, type: TypeEnum) - which opens anything (links in the browser, files, etc.)
Such a function inside itself will be already call other functions that perform specific tasks, and this function will perform only one task, determine what type is passed to it and call the necessary function to open something.
An example of a curve can but the meaning should be clear.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question