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
- Efficiency of Source.fromFile
- scala play form how handle java bigdecimal
- Dynamically add element to map after pattern matching
- SQL Database using JDBC + parameterize SQL Query + Databricks
- Using TypedADT constructs in Inox
- error after updating spark to 2.4 version
- Passing function to overloaded method in Scala
- Scala's state of type inference regarding Scalaz
- Stateful implementation of F-algebra
- Should I use the JWT token in the OAuth2 for Delivering a Secure API
- Assert RDD is not sorted
- Scala Swing component sizing
- Type safe method chaining that doesn't allow repeats of operations
- Group list of numbers into groups based on the range from the lowest number
- Best way to score current extremum in collection type
- Scala : function to measure the runtime of any other function
- Issuing native system commands in Scala
- Build Android project using AndroidProguardScala with Ant
- how to cleanup after response in akka-http complete?
- How to map an IndexedSeq to a Map collection to a collection of a different desired type in Scala?
- Scala String Equality Question from Programming Interview
- Joda Time: Convert UTC to local
- Are methods instantiated with classes, consuming lots of memory (in Scala)?
- Passing Type Constructor to Var Args of `Any` Type
- How to write an acceptance test using ScalaTest?
- Spark RDD aggregate action behaves strangely
- Spark - Stategy for persisting derived dataframes when parent DF is already persisted
- How to run docker commands in Scala?
- spray-json: Serialize a generic trait
- Is it possible to have a variable type list in Scala?