score:20
Accepted answer
To provide type information you can use a context bound
def f[T : Manifest](a:T, b:T):Array[T] = { new Array[T](2) }
or the manifest as an implicit argument:
def f[T](a:T, b:T)(implicit manifest : Manifest[T]) : Array[T] = { new Array[T](2) }
The former is syntactic sugar for the later. The manifest is needed because the type information about T is missing due to generic type errasure of the JVM.
Source: stackoverflow.com
Related Query
- cannot find class manifest for element type T
- About Scala generics: cannot find class manifest for element type T
- Cannot find JsonWriter or JsonFormat type class for a case class
- Scala-Play Form: Cannot find Formatter type class for Enumeration subtype
- Cannot find JsonReader or JsonFormat type class for List[...]
- spray-json Cannot find JsonWriter or JsonFormat type class for Class
- Spray Json: Cannot find JsonWriter or JsonFormat type class for
- Doobie cannot find or construct a Read instance for type T
- Find type class instances for Shapeless HList
- Find type class instance for Shapeless HList in Scalaz state monad
- Missing class manifest for Array of abstract type member
- How to create Dataset with case class Type Parameter ? (Unable to find encoder for type T)
- Cannot find JsonWriter or JsonFormat type class
- Java cannot find symbol for imported scala class
- Scala+Linux: Cannot find main class for jar
- Why is "Unable to find encoder for type stored in a Dataset" when creating a dataset of custom case class?
- Using the "Prolog in Scala" to find available type class instances
- could not find implicit value for evidence parameter of type org.apache.flink.api.common.typeinfo.TypeInformation[...]
- How do I declare a constructor for an 'object' class type in Scala? I.e., a one time operation for the singleton
- Could not find implicit value for evidence parameter of type scala.reflect.ClassManifest[T]
- Why is the error "Unable to find encoder for type stored in a Dataset" when encoding JSON using case classes?
- Scala: "No manifest available for type T"
- Round-up of Scalaz type class instances for other libraries
- How to access a Java static method from Scala given a type alias for that class it resides in
- Scala: Implicit evidence for class with type parameter
- Case class companion object generation error for compound type
- Writing type class instances for nested classes in Scala
- Deriving circe Codec for a sealed case class family where base trait has a (sealed) type member
- Scala compiler cannot infer mix-in type for pattern matching
- Scala Dynamic Parse Json using case class No Manifest available for T
More Query from same tag
- java.util.Enumeration in Scala
- How do I create a Scala sequence of expressions?
- Why implicit object has precedence over val in Scala 2.13-M5?
- strange behaviour in Scala : private[packageName] class A(val s:Int) hides the type A but s is still accessible from another package, why?
- Getting a spurious fibre trace with zip and for comprehension
- debug sbt sources too with eclipse
- reading a json in spark missing json datasource
- Modify element(s) in a list where a condition is true
- SBT + Lift - Not being able to build with sbteclipse
- grails stack with scala and scaml
- Alternative to Akka for handling tasks sequentially
- how to initialize a class, detail shown below
- Please suggest direction for my small scala project
- Error while parsing Date in Spark scala program
- Overcoming type erasure in Scala when pattern matching on Objects which may be different Sets or any type of Object
- UTC Dates to Long conversion: Gson - Expected a long but was BEGIN_OBJECT
- How to use ThreadLocal in scala?
- Scala polymorphism for type casting
- Apache Spark: Effectively using mapPartitions in Java
- Find Maximun area on Array
- sbt-assembly: Merge Errors - Deduplicate
- Pass an Array of arbitrary arguments to a method invoked via reflection
- How to exclude resources during packaging with SBT but not during testing
- Scala dataset map fails with exception No applicable constructor/method found for zero actual parameters
- how to find which date the consecutive column status "Complete" started with in a 7day period
- Use of "AND" operation in mapreduce
- Can Lazy modify elements in Array in Scala?
- Mac | Scala terminal error while trying to compile
- Standardize an RDD
- String ending with character in parboiled2, when the string can contain that character