上QQ阅读APP看书,第一时间看更新
Same signatures and different return types traits
What if our greeting traits have more methods that have the same signatures, but a different return type? Let's add the following declaration to FormalGreeting:
def getTime(): String
Also, add the following to InformalGreeting:
def getTime(): Int
We will have to implement these in our Greeter class. However, the compiler will not allow us the message that getTime was defined twice in, which shows that Scala prevents such things from happening.