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.

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.