Skip to content

Instantly share code, notes, and snippets.

@panda
Created May 24, 2022 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panda/8bf1db017bcf352717586f509782253d to your computer and use it in GitHub Desktop.
Save panda/8bf1db017bcf352717586f509782253d to your computer and use it in GitHub Desktop.
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))
}
@panda
Copy link
Author

panda commented May 24, 2022

syntactic sugar baby

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment