score:2
Accepted answer
i think the answer is, you can't
class testimplicits[t] {
def sayfoo(t: t)(implicit ev: foo[t]) = ev.foo(t)
def sayfooindirect(t: t) = sayfoo(t)
}
sayfoo
takes a parameter ev
, that must be provided when you are calling it, explicitly or implicitly.
in body of sayfooindirect
no implicit object of type foo[t]
is available. to make it available, either pass it implicitly everywhere or use some other way to put it in scope. as your class is fixed with type t
, you could take implicit foo[t]
in constructor.
class testimplicits[t](implicit ev: foo[t]) {
def sayfoo(t: t) = ev.foo(t)
def sayfooindirect(t: t) = sayfoo(t)
}
using this approach following will work:
val b = new bar("test")
val t = new testimplicits[bar]
t.sayfooindirect(b)
Source: stackoverflow.com
Related Query
- http(/* argument here */) How is this Object (Http) being used without an explicit or implicit method?
- Implicit without explicit imports?
- scala implicit or explicit conversion from iterator to iterable
- How do I create an explicit companion object for a case class which behaves identically to the replaced compiler provided implicit companion object?
- Automatically refactor wildcard imports into explicit imports in IntelliJ (for Scala/Java)
- Dealing with explicit parameters required by inner implicit parameter lists
- Scala implicit ambiguity doesn't get resolved without annoying dummy argument to mark the type.
- Is it possible to know what Scala implicit is being used, without the help of an IDE?
- Mock a method without arguments but with implicit parameters
- import implicit conversions without instance of SparkSession
- Why does this Scala implicit conversion fail when explicit conversion works?
- Automatic imports from multiple implicit objects
- passing & using an implicit function without defining it
- Use function without explicit import in Scala
- Using explicit value passed to implicit parameter as new implicit value
- Deterimine concrete type without explicit matching
- Scalikejdbc. Manage transactions without explicit dependency on Scalikejdbc and session
- Use Scala typeclasses directly without implicit evidence object
- Implicit parameter without type in play
- Method call (with implicit parameters) without parenthesis in scala
- Scala Implicit Classtag without changing function contract
- Scala import statement incorrectly imports implicit value
- Why does the implicit derivation of this poly function case fails without subtype evidence?
- Can I invoke case class copy method with dynamic parameter without explicit reflection?
- Using scalaz kleisli without explicit wrapping the function before
- Explicit parameters out of scope in constructor's implicit parameter list?
- Playframeworks json Writes implicit requires explicit type, why?
- Scala chaining functions when Some without explicit checks
- Implicit conversion happens without importing implicit?
- case class explicit parameters that are implicit inside
More Query from same tag
- sbt run Play as a sumodule
- Parallelism: rdd.parallelize(....) vs dataSet.map(...)?
- Difference between static controller and non static controller in play framework with Java
- How to create partial function from runtime value in Scala
- How can I extract date from a .txt file which name contains date? (Scala)
- Null checks for scala XML attributes
- Is it possible to implicitly get a builder for a collection, as in the old CanBuildFrom?
- emit multiple objects from PushPullStage
- How to move files from one folder to another?
- java.io.FileNotFoundException: File file:/data/home/test/analysis.json does not exist. Spark error while reading json
- Spark - GSSException: No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt)
- publish jar files with sbt (3rd party)
- Need help to check scala code can be made concise. Find all factors of n
- Understanding build.sbt with sbt-spark-package plugin
- Scala Spark: how to add list of generated methods to a function
- How To create dynamic data source reader and different file format reader in scala spark
- Efficient way to match case object in scala
- Split a list into sublist based on element types in scala
- Combining two columns, casting two timestamp and selecting from df causes no error, but casting one column to timestamp and selecting causes error
- spark dataframe pivoting is throwing AssertionError: assertion failed: unsafe symbol Unstable
- PlayFramework(2.6.12): Use JKS file in conf folder(relative path) in HTTPS mode
- why adding a multi-line comment in the code makes it uncompilable
- Problems compiling and running Scala projects in IntelliJ Idea
- How to properly use akka actors in scala
- Sbt Assembly Include Conf Files inside the JAR
- Scala and AKKA for a simulation
- Apache-Spark - Weird classes with FieldAccess suffix were loaded
- Load multiple JSON files in spark sql from S3. Performance issue
- Running Scala jobs in Scheduler
- Scala: Extend concrete class with constructor parameters