Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Would it be possible to have "method/field" literals comparable to the class literals in Java/Scala?

Java's Foo.class as well Scala's classOf[Foo] literal class syntax return a reflective view about the class in question.

Is it possible and would it make sense to provide something like .method/.field or methodOf[]/fieldOf[] for getting comparable reflective access to methods and fields?

How would something like this be implemented in Java/Scala?

In the case of Java, I would assume that this would either require a language change (very unlikely) or some wizardry with bytecode tools/AspectJ, whereas in Scala it is probably possible to implement it with an implicit conversion.

like image 679
soc Avatar asked Dec 27 '22 14:12

soc


1 Answers

Yes and no. Paul Phillips has certainly expressed an interest in such a thing, and there's a lot of work currently happening in trunk around the forthcoming scala reflections.

It's doubtful that we'll see anything like your proposed syntax though. Methods are not a first-class construct and, as such, and only be referenced via their containing class. But we will be getting a nice scala-friendly way to access members via reflection, including default params, parameter names, etc.

like image 158
Kevin Wright Avatar answered Jan 11 '23 13:01

Kevin Wright