score:96
Accepted answer
scala> Main.getClass
res1: java.lang.Class[_] = class Main$
score:9
Since Main is an object, for your example to work, simply replace your assignment line with;
private [this] val TAG = this.getClass.getName;
score:17
The reason why classOf[Main]
doesn't work is because Main
is not a type.
Classes and traits define types, objects do not.
Source: stackoverflow.com
Related Query
- How the get the classOf for a scala object type
- Scala classOf for type parameter: how to call the function and how to restrict with upper type bounds
- How can I get the actual object referred to by Scala 2.10 reflection?
- How to get an java.lang.Class of a scala object for an annotation argument
- How do I get the runtime Class of a parameterized Type in a Scala trait
- How to ask for the same type in Scala generics without introducing a third type parameter?
- Scala - how to get the 'type' for a field using reflection api
- How can I get random data generated for scala case classes with the ability to "change some values" for unit testing?
- In scala macros, how to get the complete `extends` clause for a class?
- Scala 2.10 reflection: Why do I get the same type "List()" for the list and list element?
- How to get the proper return type when using a filter based on type in Scala
- How to see the type of a scala variable? For instance a Spark PairRDD
- How to get the COUNT of emails for each id in Scala
- How can an object in Scala be cast to the intersection of its own type and any unrelated trait?
- Scala runtime reflections get all the members of a specific type even for inner classes
- Scala Macros: How to get a Type object of a generic List
- How to get an object's specific type and cast the object to it in Scala?
- Scala Def Macros - How do I get the parameterized type member of a symbol?
- In Scala, how to use reflection to get the real type of varargs parameters for method
- How can I access the companion object of a Scala class passed as a type param?
- How to get the type parameters from an abstract class that is extended by an object
- How do I get the type signature to agree with the scala compiler when extracting a value out of an Option[A]?
- How do I get the class object of Class with type parameters in Scala?
- get the type parameter for a Scala type
- How to get the class of a trait within an object defined in scala from within a java class?
- In Scala how to check the runtime type of an object in base trait
- How can I get the Scala compiler to infer the type of this function?
- How to get the aliased type of a type alias in scala runtime?
- For loop in Play Framework, how to get the name of an object
- How to get the actual type of primitive type parameter in Scala Seq[T] or Option[T]?
More Query from same tag
- Play! dist throws Exception
- sbt dependencies ignoring version
- Extract list to multiple distinct list
- Executing Scala via TextMate
- Scala - Dequeue doesn't return correct result
- Spark: Convert column of string to an array
- how to apply partition in spark scala dataframe with multiple columns?
- Scala akka: declare a global variable in receive function
- How to run Scala test in Scala native application?
- Streaming query not showing any progress in Spark
- How to send iterables between actors or from an actor to a Future?
- Adding a attribute to json file
- Play Framework & Scala: Mocking a method from with class
- How to understand the use of supertypes and variance in Scala's Option?
- How to set Lift run mode on App Engine
- What wrong in this scala code
- Server side pagination in Graphql Scala
- Socket connection and ActorSystem
- Scala cake pattern with Existential Types: compile error
- Scala var type usage results in type mismatch
- Weird type erasure for Option in nested collection
- Why does Ordered[A] use a compare method instead of reusing compareTo?
- Is there an equivalent of Java's this in Scala constructors?
- Authenticate using ajax in Play 2.1
- Memory being filled up in Spark Scala
- How do you uninstall the Scala Eclipse plugin?
- scala map / type instantiation
- Scala domain object modeling
- Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.2
- Perform arithmetic on a list in Scala