companion-object Questions

1

Solved

Please refer to the source code below. All source code is defined in the same package. When I define all of the code within a single source file ShowMain.scala, I get a compile error, however when ...
Effie asked 24/8, 2014 at 4:37

3

Solved

I have a case class defined as such: case class StreetSecondary(designator: String, value: Option[String]) I then define an explicit companion object: object StreetSecondary { //empty for no...
Chute asked 19/8, 2014 at 20:28

2

Solved

I'm wondering, why can't a class get an access to a companion object's field? class MyClass { println(val1) // not found, why? } object MyClass { val val1 = "str" } It should, it should even ...
Tall asked 20/11, 2013 at 17:41

1

Solved

I am looking at Akka related typesafe activator code and the following construct intrigued me: Companion object: object MarkerActor { sealed trait MarkerMessage case object Stop extends MarkerM...
Tetter asked 16/5, 2014 at 21:24

1

Solved

Using a Scala 2.10/2.11 macro paradise annotation macro, how can I add or extend the companion object of an annotated class? Skeleton: import scala.annotation.StaticAnnotation import scala.reflect...
Yadirayaeger asked 9/1, 2014 at 22:51

1

Solved

I am kind of blocked with the following (macro annotation) situation. Suppose I have an annotation called @factory which aims to generate an apply method for the annotated trait in the correspondin...
Peignoir asked 15/10, 2013 at 10:54

2

Solved

class Foo { final val pi = 3 } Does every Foo object have a pi member? Should I therefore put pi in the companion object?
Photoelectrotype asked 12/7, 2013 at 13:21

1

Solved

I need to define a val in my companion object which is initialized with a method which takes the companion class as parameter. I want to handle this with traits to not repeat myself. My Problem is...
Danseur asked 13/6, 2013 at 10:52

2

Solved

i needed two instances that has access to each other privates. i naturaly thought of a companion object that grants access to a one and only instance of it's companion class. the class itself i mad...
Eisenstark asked 14/1, 2013 at 14:48

1

When defining a case class, the default companion object has nice curried method to get a curried version of the case class constructor: scala> case class Foo(a: String, b: Int) defined class F...
Rapids asked 20/10, 2012 at 13:25

3

Solved

object ScalaTrueRing { def rule = println("To rule them all") } this piece of code will be compiled into java byte code, if I decompile it, then the equivalent Java code is similar to this: pub...
Luckett asked 8/10, 2012 at 14:40

8

Solved

I am teaching Scala for the first time and my students are finding the deliberate "punning" involved in companion objects very confusing. Consider the following example: class Stack { ... methods...
Anchoress asked 19/9, 2012 at 14:30

2

Solved

I have a class and its companion object which together have some reusable functionality. I have encapsulated the functionality of the companion object into a trait, so now the situation is like cl...
Paper asked 29/8, 2012 at 13:28

1

Solved

A Scala class's "companion object" can be viewed as a singleton object with the same fully qualified name as the class (i.e. same name, in same package). They are used to hold utility functions com...

2

Solved

A rather weird behavior coming from the Scala REPL. Although the following compiles without a problem: class CompanionObjectTest { private val x = 3 } object CompanionObjectTest { def testMetho...
Eschatology asked 2/8, 2011 at 23:30

2

Solved

I'd like to add implicit conversions to Java classes generated by a modeling tool. So I want to add them to the companion object of those classes, so that the compiler automatically finds them. But...

2

Solved

I'd like to write a type alias to shorten, nice and encapsulated Scala code. Suppose I got some collection which has the property of being a list of maps, the value of which are tuples. My type wou...
Aquanaut asked 13/10, 2010 at 3:25

4

Solved

When you create a case class, the compiler creates a corresponding companion object with a few of the case class goodies: an apply factory method matching the primary constructor, equals, hashCode,...
Dysphonia asked 15/6, 2010 at 21:58

3

Solved

In Scala, if I define a method called apply in a class or a top-level object, that method will be called whenever I append a pair a parentheses to an instance of that class, and put the appropriate...
Contemporary asked 3/8, 2009 at 18:18

© 2022 - 2024 — McMap. All rights reserved.