Static Reflection in Scala
Aravindh S <[email protected]>
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <[email protected]> |
Hi All, I have been trying to achieve the following in scala for quite
sometime now, but was not able to do so. I am looking for a way to pass
the name of a val inside a case class along with its type to another
method. Below is an example:
case class Person(name:String, age:Int)
object Sample{
def apply[T]={}
def set(???) = ???
}
I would like the set method to be used like
Sample[Person].set(p => p.name = "random name") or simply
Sample[Person].set(_.name="random name")
The above ideally wont work because I am trying to re assign to a val. But
Would like to have something like this. I need to capture the name of the
val, type of the val inside the set method and would want the compiler to
do a type check when the above method is invoked.
In C#, We have the expression API which helps in static compile time
reflection which will allow you to define methods like above. How do I
accomplish the above in scala?
Thanks
Aravindh.S
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.