score:9
Actually, Scala does have runtime-retained annotations. The difference is that they are not stored as Java annotations but are instead encoded inside the contents of binary ScalaSignature
annotation (which, by itself, is a runtime-retained Java annotation).
So, Scala annotations can be retrieved at runtime, but instead of using Java reflection, one must use Scala reflection:
class Awesome extends StaticAnnotation
@Awesome
class AwesomeClass
import scala.reflect.runtime.universe._
val clazz = classOf[AwesomeClass]
val mirror = runtimeMirror(clazz.getClassLoader)
val symbol = mirror.classSymbol(clazz)
println(symbol.annotations) // prints 'List(Awesome)'
Unfortunately, Scala reflection is still marked as experimental and is actually unstable at this point (SI-6240 or SI-6826 are examples of quite serious issues). Nevertheless, it seems like the most straightforward replacement for Java reflection and annotations in the long term.
As for now, one has to use Java annotations which I think is still a nice solution.
Regarding frameworks and libraries for DI/ORM/WS/serialization - Scala still doesn't seem to be mature in this area, at least not as Java is. There are plenty of ongoing projects targeting these problems, some of them are already really nice, others are still in development. To name a few that come to my mind: Squeryl, Slick, Spray, Pickling.
Also, Scala has some advanced features that often make annotations unneccessary. Typeclasses (implemented with implicit parameters) are probably good example of that.
Source: stackoverflow.com
Related Query
- What's the scala alternative to runtime-preserved annotations
- What Scala annotations modify the compiler's messages?
- Any way to access the type of a Scala Option declaration at runtime using reflection?
- Getting the string representation of a type at runtime in Scala
- Getting the scala compiler to work inside an OSGi runtime
- Is there a way to create custom annotations in Scala and write a custom annotation processor to verify the annotations?
- How to get the runtime value of parameter passed to a Scala macro?
- Why is it faster to call external scala compiler than use the runtime interpreter library?
- How do I get the runtime Class of a parameterized Type in a Scala trait
- Whats the equivalent to String... in scala
- How can I ensure that the dynamic type of my custom Scala collection is preserved during a map()?
- Scala runtime reflections get all the members of a specific type even for inner classes
- Whats the scala way to do this
- How do you check if a runtime instance conforms to some type using the Scala 2.10 reflection API?
- Get the explicit type of a generic parameter at runtime in Scala
- Measure the function-level memory usage in Scala in my Application Code during runtime
- Scala runtime compilation: how to get line number of the error message?
- Is there an alternative to the deprecated enclosingClass method in Scala refelection library?
- Whats the scala spark equivalent of subset of R
- In Scala how to check the runtime type of an object in base trait
- How to know in scala runtime the different join types spark
- Whats the difference between main and secondary methods in scala and how to execute mulitple functions in the scala class?
- Check the runtime type of Scala class instance
- How to get the annotations of a method in Scala 2.11
- Scala check at runtime whether an object has a the same type as a given parameterized type of a method invocation
- How do I set up Scala plugin for NetBeans to copy the Scala runtime library?
- How to reflect concrete return types for methods of classes defined at runtime using the Scala ToolBox?
- Scala : function to measure the runtime of any other function
- Scala : function to measure the runtime of any other function
- Alternative to the use of the 'withColumn' function in Spark Scala
More Query from same tag
- Conditionally merge list elements
- Scala - Vals and Defs - Decompiled
- Scala class value without an instance
- Writing function parameters before function to be applied in Scala
- Multiple flatMap methods for a single monad?
- OneHotEncoder with input being an array
- Map frequently changing JSON value to corresponding element in Scala
- How to configure SBT to produce separate jars for dependencies and application code?
- Type mismatch for a simple secure social play 2 app
- Processing Future Comprehension Scala
- Approaches to testing that a method is not available on a type
- Serialize objects as JSON primitive type in Scala (Play Framework)
- Dataframe transformations produce empty values
- Training/Test data with SparkML in Scala
- Twitter Logging and Scala Custom Handlers
- Writing SQL in Play with Scala?
- In Lift, changing the way Menu.param behaves
- Proper use of Scala traits and case objects
- Scala type signature failing with subclasses
- How to find duplicates in a list?
- Pimp my library pattern applied to class hierarchy
- Building dynamic aggregation queries for elasticsearch using elastic4s client
- Cast Type Alias to generic type without the use of package object
- Spark: UDF not reading already defined value
- New sbt "feature" configuration not found in X / unresolved (transitive) dependencies
- Where did evaluating and produce go in ScalaTest 3?
- How to compose function to applicatives with scalaz
- Scala passing method to supers constructor
- Deserialize BigDecimal in scala with json4s return empty list
- Java Akka Actors - Message throttling and priority