Getting java constructor parameter names via scala reflection

86 views
Skip to first unread message

Aravindh S

unread,
Jul 11, 2015, 10:40:09 AM7/11/15
to scala-l...@googlegroups.com
Hi,
 I am trying to get the names of constructor parameters of a java class using scala reflection. I have the following:
Tender.java
public class Tender {
public String name;
public int age;

public Tender(String name,int age){
this.name = name;

this.age = age;
}
}

Program.scala
def classAccessors[T: TypeTag] = typeOf[T].members.head.asMethod.paramLists

private val symbols = classAccessors[Tender]

I am getting the value of symbols as List(List(value x$1, value x$2))
I want the actual names viz `name` & `age` rather than x$1 & x$2. Is there any way to accomplish this?


Thanks
Aravindh.S

Jon Pretty

unread,
Jul 14, 2015, 3:30:12 PM7/14/15
to scala-l...@googlegroups.com
Cheers,
Jon

--
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 scala-languag...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jon Pretty | @propensive

Juha Heljoranta

unread,
Jul 30, 2015, 8:54:04 AM7/30/15
to scala-l...@googlegroups.com, Aravindh S
Reply all
Reply to author
Forward
0 new messages