scala - What is a Singleton Type exactly? -
what singleton type? applications, implications ?
examples more welcome , layman terms more welcome !
if think of type set of values, singleton type of value x type contains value ({x}). usage examples:
pattern matching:
case _: foo.typechecks matched object samefoousingeq,case foochecks it's equalfoousingequals.it's needed write down type of
object(as type parameter, argument, etc.)for mutable objects guarantee return value of method object (useful method chaining, example from here):
class { def method1: this.type = { ...; } } class b extends { def method2: this.type = { ...; } }you can call
new b.method1.method2, couldn't withoutthis.typebecausemethod1returna.
Comments
Post a Comment