I have a class
class MyClass {
def apply(myRDD: RDD[String]) {
val rdd2 = myRDD.map(myString => {
// do String manipulation
}
}
}
object MyClass {
}
Since I have a block of code performing one task (the area that says "do String manipulation"
), I thought I should break it out into its own method. Since the method is not changing the state of the class, I thought I should make it a static
method.
How do I do that?
I thought that you can just pop a method inside the companion object and it would be available as a static class, like this:
object MyClass {
def doStringManipulation(myString: String) = {
// do String manipulation
}
}
but when I try val rdd2 = myRDD.map(myString => { doStringManipulation(myString)})
, scala doesn't recognize the method and it forces me to do MyClass.doStringManipulation(myString)
in order to call it.
What am I doing wrong?