There is a class (specifically TypedPipe[T] in com.twitter.scalding) that has only a private constructor, and I wish to add some methods to it. It looks something like this
class TypedPipe[+T] private ( a : Int) {
}
This is usually done by defining an implicit conversion method. However, I need access to a to define the method I want to. Is this simply impossible in Scala?
If I correctly interpreted your question, the answer is yes, this is simply impossible in Scala.
This has nothing do to with the private constructor. If it were public, you would have exactly the same problem.
The point here is that there is no
valorvarbeforea.ais not a property ofTypedType, but only an argument to its constructor, i.e. no property is created to hold the value of a inside the objectThis is equivalent to the Java code:
and you can actually check it out easily with the REPL. If you want
ato be accessible outside the constructor, it must either be avaror avalI am a big fan of the javap disassembler in the REPL:
As you can see, in the first version there is no member property to hold the value of
a, and no getter