2

What's the meaning of "_" in Seq[Dependency[_]] and RDD[_] for the following code

abstract class RDD[T: ClassTag](
    @transient private var sc: SparkContext,
    @transient private var deps: Seq[Dependency[_]]
  ) extends Serializable with Logging {

  /** Construct an RDD with just a one-to-one dependency on one parent */
  def this(@transient oneParent: RDD[_]) =
    this(oneParent.context , List(new OneToOneDependency(oneParent)))
Ian Roberts
  • 117,925
  • 15
  • 163
  • 179
Daniel Wu
  • 5,575
  • 12
  • 39
  • 85

1 Answers1

6

It's just a wildcard.
You can use a wildcard for a type parameter.

Quantification

Sometimes you do not care to be able to name a type variable, for example:

scala> def count[A](l: List[A]) = l.size
count: [A](List[A])Int

Instead you can use “wildcards”:

scala> def count(l: List[_]) = l.size
count: (List[_])Int

This is shorthand for:

scala> def count(l: List[T forSome { type T }]) = l.size
count: (List[T forSome { type T }])Int

From http://twitter.github.io/scala_school/type-basics.html

Naetmul
  • 13,318
  • 6
  • 54
  • 80
  • Is RDD[_] in def this(@transient oneParent: RDD[_]) the same as RDD[T]? Since class is abstract class RDD[T: ClassTag], and it defined T. – Daniel Wu Feb 09 '14 at 13:50