E084: Wildcard On Type Argument Not Allowed On New
This error is emitted when a wildcard type argument (? or _) is used in a new expression.
When creating a new instance, the compiler needs to know the exact types to allocate and initialize the object. Wildcard types are unknown types that can't be instantiated directly.
Example
class Team[A]
val team = new Team[?]
Error
-- [E084] Syntax Error: example.scala:3:20 -------------------------------------
3 |val team = new Team[?]
| ^
| Type argument must be fully defined
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| Wildcard on arguments is not allowed when declaring a new type.
|
| Given the following example:
|
|
| object TyperDemo {
| class Team[A]
| val team = new Team[?]
| }
|
|
| You must complete all the type parameters, for instance:
|
|
| object TyperDemo {
| class Team[A]
| val team = new Team[Int]
| }
|
-----------------------------------------------------------------------------
Solution
// Use a concrete type argument
class Team[A]
val team = new Team[Int]
// Or let the compiler infer the type from usage context
class Team[A](member: A)
val team = new Team("Alice")
In this article