My problem is that I cannot really nail my head when they happen, and when they do not.
They occur when an implicit parameter is required. If we look at the definition of a method, we will see:
def addSource[T: TypeInformation](function: SourceFunction[T]): DataStream[T]
But we do not see any implicit parameter, where is it?
When you see a polymorphic method, where the type parameter has the form
def foo[T : M](param: T)
Where T is a type parameter, and M is a context binding . This means that the creator of the method requests an implicit parameter of type M[T] . This is equivalent to:
def foo[T](param: T)(implicit ev: M[T])
In the case of your method, it actually expands to:
def addSource[T](function: SourceFunction[T])(implicit evidence: TypeInformation[T]): DataStream[T]
This is why you see a compiler complaint, since it cannot find the implicit parameter that the method requires.
If we go to the Apache Flink Wiki, under Enter information , we can understand why this is happening:
No implicit value for proof parameter error
In the event that TypeInformation cannot be created, programs cannot compile with an error, stating that "it was not possible to find an implicit value for the proof parameter of type TypeInformation". A common reason if the code generating the TypeInformation not been imported. Be sure to import the entire flink.api.scala package. import org.apache.flink.api.scala._
For general methods, you will need to require them to generate TypeInformation on the call site website:
For general methods, the data types of the function parameters and the return type may not be the same for each call and are not known on the site where the method is defined. The above code will lead to an error in which not enough hidden data will be received. In such cases, type information should be generated on the call site and passed to the method. Scala offers implicit parameters for this.
For your types, this means that if the invocation method is generic, it also needs to request a context binding for this type parameter.