Created
May 24, 2022 01:37
-
-
Save panda/8bf1db017bcf352717586f509782253d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package playground.scala | |
/** | |
* Created by steve on May 2022 | |
*/ | |
object MethodNotations extends App { | |
class Person(val name: String, favoriteMovie: String) { | |
def likes(movie: String): Boolean = { | |
movie == favoriteMovie | |
} | |
def hangOutWith(person: Person): String = | |
s"${this.name} is hanging out with ${person.name}" | |
} | |
val steve = new Person("Steve", "Breaking Bad") | |
println(steve.likes("Breaking Bad")) // true | |
println(steve.likes("Broke Bad")) // false | |
// scala | |
println(steve likes "Breaking Bad") // infix notation = operator notation | |
// new person | |
val jerry = new Person("Jerry", "The social network") | |
println(steve hangOutWith jerry) | |
println(steve.hangOutWith(jerry)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
syntactic sugar baby