Questions tagged [classtag]

22 questions
0
votes
1 answer

What is the meaning of a generic type like "C: ClassTag : Manifest"?

I found some snippets as follow: import org.json4s.DefaultFormats import org.json4s.jackson.JsonMethods._ import scala.io.Source import scala.reflect.ClassTag class ConfigLoader[C: ClassTag : Manifest](filePath: String) { def loadFromFile(): C…
0
votes
2 answers

How to initialize variable of Type in Scala?

I'm new to scala, sorry for the dumb question. I want to remove the return statements from this Scala code (my real case is much more complicated than this) def readValue[Type](value: Any)(implicit tag: ClassTag[Type]): Type = { if (value ==…
elaspog
  • 1,635
  • 3
  • 21
  • 51
0
votes
0 answers

Converting scala list to array

When I try to do this, it works fine val list = List(1,2,3,4,5) val array = list.toArray But I am trying to understand the implicits that happen behind the scenes. The signature of toArray is [B >: Int](implicit evidence$1 : classTag[B]) Any…
Srinivas
  • 2,010
  • 7
  • 26
  • 51
0
votes
1 answer

Scala get classtag from class instance

I need to write a generic method to get all fields of an object and it's value, the class of this object may contains ClassTag, so we should find a way to get it as well, is any way good way ? the difficulty is we don't know the class ahead, it may…
Jerry Wu
  • 21
  • 1
  • 4
0
votes
1 answer

No ClassTag available for A - but implicit parameter present

Using scala 2.12.4 I cannot get this code to work since it says [error] .../src/main/scala/effect.scala:32:11: No ClassTag available for A [error] Effect(effectDefinition) [error] ^ [error] one error found [error]…
winson
  • 388
  • 1
  • 9
0
votes
0 answers

Scala, ClassTag and Guice: Error injecting constructor, java.lang.StackOverflowError

In my Play 2 application, I need to create a class tag in the class which is instantiated by Guice (as an eager singleton; this is a requirement). case class UserCreated(id: Long, userName: String) extends ApplicationEvent @Singleton class…
Teimuraz
  • 8,795
  • 5
  • 35
  • 62
0
votes
1 answer

json4s JValue scala classTag works wrong

In my code, I use classTag[JValue] want to get org.json4s.JsonAST.JValue , but actually it returns org.json4s.JsonAST$JValue, it is strange ! why there is the $? I am new guy use scala ,could someone answer me ? thanks a lot
yang_song
  • 24
  • 3
1
2