Simple question, I have code like this:
class Context[A] {
def t: A
}
object Context {
implicit object StandardContext extends Context[SomeObject] {
def t = SomeObject
}
}
SomeObject is an object that holds values and functions that I would like to access in my Context. Unfortunately the different types for A I would like to include do not have a common parent class, other than java.lang.Object.
SomeObject is defined like this:
final object SomeObject {
def func1 = ...
def func2 = ...
}
In some code that’s not mine. But the Scala compiler complains SomeObject is not a value when I try the thing above. As far as I know it, an object in scala is a singleton class, so it would be a type, yes, but also a value, the only value of its own type.
What I wanna do is stuff like this:
class Foo[A](bar: Int)(implicit context: Context[A]) {
def baz = context.t.baz
}
Anyone can tell me how to solve this or have a better idea of solving it?
The first SomeObject is a type, a type-parameter for Context, but in the second row it is used as if it were a variable.
Think of
Int is a type, not a variable, so
xcan’t returnInt, it could only return an integer.