Re: Static Reflection in Scala

rssh <[email protected]>
Newsgroups gmane.comp.lang.scala
Message-ID <[email protected]>
 

API overview: http://docs.scala-lang.org/overviews/reflection/overview.html 
and http://docs.scala-lang.org/overviews/macros/usecases.html

Also you can look at code which do very simular task:
 https://github.com/rssh/scala-gopher/blob/master/src/main/scala/gopher/util/ReflectUtil.scala

 (retrieve all vals)
and in 
https://github.com/rssh/scala-gopher/blob/master/src/main/scala/gopher/transputers/ReplicateTransputer.scala
near line 202 you will see  retrieving tree where variable with the same 
type as defined in given class, is defined.


On Sunday, February 8, 2015 at 7:07:50 AM UTC+2, Aravindh S wrote:
>
> 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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.