score:17
Yes, you do, just as you state. There's access, and there's scope -- what companion class/objects have is access, not scope.
It's like declaring something public vs private -- it doesn't bring those members into everyone's scope, just give them access to it.
score:3
Yes (and I want my 15 points for that!)
But to expand, their scopes do not overlap, so the import is necessary.
score:4
"Can access private members" means that the following works:
object Foo {
private def bar = 4
}
class Foo {
def foo = Foo.bar
}
Source: stackoverflow.com
Related Query
- Do I need to import members of a singleton object into its companion class in Scala?
- Companion class requires import of Companion object methods and nested objects?
- An object extends its companion case class in Scala
- What's the difference between a companion object and a singleton class in Scala (Guice)
- Why is my companion object cannot access method in its companion class
- Singleton Object vs Companion Object in Class
- scala: class can't access companion object members externally
- Error: class file needed by ValidDateOrNumericTypeHolder, need RegisterJodaTimeConversionHelpers() - its hopeless, I can't find the import
- Why can a companion object access a private val in its companion class when compiling, but cannot do that when interpreting?
- Reflection: Getting module mirror from inner class mixed into a singleton object
- Scala Play Guice using injector to manually inject a singleton class that has configuration injected into its constructor
- scala use same logger into class and companion object
- Class cannot access its Companion object. (with import and class name)
- Is there a way to make companion object function private and import the companion object to the class and then access the function?
- Case class Members not accessible via Companion Object
- Using .tupled method when companion object is in class
- Get companion object of class by given generic type Scala
- Scala: order of definition for companion object vs case class
- What's the difference between a class with a companion object and a class and object with the same name?
- Case class and companion object
- In Scala, how can I define a companion object for a class defined in Java?
- Why is a Scala companion object compiled into two classes(both Java and .NET compilers)?
- How to get the class of a singleton object at compile time?
- How do I create an explicit companion object for a case class which behaves identically to the replaced compiler provided implicit companion object?
- Case class companion object generation error for compound type
- Can't access method of companion class from companion object
- Why aren't the members of my nested companion object automatically visible in the class?
- Companion object cannot access private variable on the class
- Why do people define object extends its companion class?
- Why can't I access private class methods in the class's companion object in Scala?
More Query from same tag
- No Log4J output in sbt when using scalatest
- android - Scala OnClickListener AlertDialog
- java.lang.IndexOutOfBoundsException: No group 1 | Pattern matching
- Scala: How to cast this if-then-else ladder as pattern matching
- Scala wrong type inference
- How to fix infinity redirect in Akka HTTP?
- spark scala json string to json object customed
- Scala style with Futures
- Update Column in Spark Scala
- pick up different source file for different Scala version
- Force passing a type parameter
- Can commands be written to support multi-line arguments, i.e. with new lines in them, as heredocs?
- Combining a list of tuples
- Inter-process communication between Python and Scala programs
- Failed to apply plugin [class 'org.gradle.api.plugins.scala.ScalaBasePlugin']: Gradle v2.13
- How to control priority of implicit conversions applied on method arguments?
- How to failed compilation if there are any dead code or unused imports, variables etc
- Getting a null with a val depending on abstract def in a trait
- var_dump() in Scala
- Spark write operation HDFS using temporal path
- What is "WARN ParallelCollectionRDD: Spark does not support nested RDDs (see SPARK-5063)"?
- How to find minimum and maximum of points in x and y coordinates
- Writing a Java class inside my Scala application
- Built-in way to simulate a while loop without side effects
- print float without scientific notation in scala
- Akka Streams WebSocket to send info on arbitrary events
- Methods versus Function and implicits in Scala
- Spring boot with scala in maven intelliji not auto compiling
- Reading JSON object with JSONArray inside to RDD using Scala and without using Dataframe
- Why does merging with empty fs2.Stream change program's behavior