sathi_reddy
sathi_reddy

Reputation: 11

What is for square brackets in scala when we use them before declaration of trait or object

I have seen below code in Scala Redis client. What does [redis] will do?

package object redis {
  private[redis] trait Reply
  private[redis] trait R extends Reply
  private[redis] object Commands
}

Upvotes: 1

Views: 388

Answers (2)

Tim
Tim

Reputation: 27356

private[redis] means that the trait or object is only usable by code inside the redis package. Code in other packages cannot access the value.

Upvotes: 1

pedrorijo91
pedrorijo91

Reputation: 7845

that means a method/class/object/trait is only visible to other classes in the same package.

Is one of the existing scala access levels:

  • Public
  • Package private
  • Package
  • Private

See more details at https://alvinalexander.com/scala/how-to-control-scala-method-scope-object-private-package

Upvotes: 1

Related Questions