In "package X" How to disambiguate "Overload resolution ambiguity:" same fun name in 2 files

H folks. In “package Aquarium” I am getting the following error.

Error:(22, 5) Kotlin: Overload resolution ambiguity: 
public fun prObj(msg: String, myObj: Any): Unit defined in Aquarium in file AquariumFish.kt
public fun prObj(msg: String, myObj: Any): Unit defined in Aquarium in file Main.kt

How can i disambiguate this situation at fun call without renaming the function?

Thanks.
Love and peace,
Joe

Use fully qualified name or import prObj as otherPrObj. But the general rule is to avoid same name top-level functions.

Thanks, darksnake. Would you please show me an example of “fully qualified name” for the case I described?

Thanks again.
Love and peace,
Joe

<your.package>.prObj(msg,obj) should do the trick if your methods are in different packages. If they are top level functions in the same package - it is not allowed. They have the same fully qualified name in kotlin (but not in JVM).

If you are bent on placing top level functions with the same name in the same package, you can introduce namespace object like:

object AquariumFish{
    fun prObj(msg: String, myObj: Any)
}

But the general idea is not to abuse top level functions.

Thanks, darksnake. I need to COGITATE :blush: on what you said.

I need to figure out for IDEA Projects, the meaning of Top Level vs Package Level.

Thanks again, darksnake.
Love and peace,
Joe

Top level and package level are the same. This means that they are not a member of a class or object.

A Ha! Thanks, darksnake.
More thinking is necessary.
But as we used to say at IBM,
I am STILL confused, BUT at a HIGHER LEVEL. :smiley:

I found this article that I THINK will help me think about things relative to my newly upgraded state of confusion:
Daily Kotlin: Static methods

Thanks again, darksnake.
Love and peace,
Joe

I recommend not to read about statics if you are not coming from java background. Kotlin does not have statics in the language. What you have are naming scopes. Package is a scope since full name of class, property or function includes package name. Class or object is also a scope.

The full name of entity is <package.name>... To entities with the same name and signature (for function signature consists of parameter types and in some cases return type) obviously can’t exist simultaneously since compiler can’t distinguish between them. So in order to have two functions with the same name and parameters, you need to either place them in different packages or in different classes.

Top level functions are called that way because they are not placed inside class. They are not big deal if you are coming from procedural language like Fortran or Python. But in Java they are not allowed, so they are usually confusing for Javists.

1 Like

Thanks again, SO MUCH, darksnake.
Re: “not coming from java background … coming from … Python”.
You have understood my challenge. My Java experience has been augmented by lots of Python, JavaScript and Node.js.
Thanks for your patience and insight.
Love and peace,
Joe