2

I found the following syntax in Scala. I have never seen # and couldn't find much information about it? What does # mean?

case class WithRole(role: Role) extends Authorization[User, DefaultEnv#A]
Manu Chadha
  • 15,555
  • 19
  • 91
  • 184

1 Answers1

1

It's one of way in scala to refer a type. I quote from Scala in Depth:

Types within Scala are referred to via two mechanisms: the hash ( #) and dot ( .) operators. The dot operator can be thought of doing the same for types as it does for members of an object. It refers to a type found on a specific object instance. This is known as a path-dependent type. When a method is defined using the dot operator to a particular type, that type is bound to a specific instance of the object. This means that you can’t use a type from a different object, of the same class, to satisfy any type constraints made using the dot operator. The best way to think of this is that there’s a path of specific object instances connected by the dot operator. For a variable to match your type, it must follow the same object instance path. You can see an exam- ple of this later. The hash operator ( # ) is a looser restriction than the dot operator. It’s known as a type projection, which is a means of referring to a nested type without requiring a path of object instances. This means that you can reference a nested type as if it weren’t nested.

wqlin
  • 58
  • 1
  • 5