brand new, and have a question; we were going over...
# getting-started
t
brand new, and have a question; we were going over something in class and I wasn't able to get an answer; Can someone please tell me what the difference is between the first two photos and the last two photos? They use the same methods of interpolation, but my instructor was trying to emphasize that the first two won't work because the interpolation is happening within the println statement... but the last images are proof that it does work inside the println statement; I am so confused. Thread in Slack Conversation
a
It looks like you are calling print inside your functions, rather than having your functions return a value to be interpolated by the calling print statement.
i.e. your code looks a bit like this:
Copy code
val myInterfaceObject = InterfaceImplementation()

class InterfaceImplementation: SomeInterface {
    override fun displayInfo() {
        println("Hello from the displayInfo")
    }

    override fun dispayMoreContent() {
        print("This is more content")
    }

    override val myName: String
        get() = "value"

}

interface SomeInterface {
    fun displayInfo()
    fun dispayMoreContent()

    val myName: String
}


println("My Variable value is ${myInterfaceObject.myName}")
println("Call the displayInfo ${myInterfaceObject.displayInfo()}")
println("Call the interface method ${myInterfaceObject.dispayMoreContent()}")
When it should look something like this:
Copy code
val myInterfaceObject = InterfaceImplementation()

class InterfaceImplementation: SomeInterface {
    override fun displayInfo(): String {
        return "Hello from the displayInfo"
    }

    override fun dispayMoreContent(): String {
        return "This is more content"
    }

    override val myName: String
        get() = "value"

}

interface SomeInterface {
    fun displayInfo(): String
    fun dispayMoreContent(): String

    val myName: String
}


println("My Variable value is ${myInterfaceObject.myName}")
println("Call the displayInfo ${myInterfaceObject.displayInfo()}")
println("Call the interface method ${myInterfaceObject.dispayMoreContent()}")