I don’t know exactly where to post this to get the most attention from the JCP, so I just thought I would put it on my blog and ask the readers to kindly link it appropriately so it reaches the right pairs of eyes. Apologies if this post sounds more like a rant; in some respects, it is.
I’ll tell you what I really, really need from a future version of Java. This is where I’m coming from: I’m going to be using a language where I have to spoonfeed the compiler by declaring the types of my variables, parameters, methods, collections (with the addition of generics, even more than that), and sometimes I want to do some whacky dynamic programming with proxies, CGlib or just good old-fashioned wrestling with the bytecode in a pool of mud.
In those cases, I want to be able to isolate the dynamic whackiness as much as possible from the rest of my “sane” code. I want to make my code read as nicely as possible, given the constraints and inherent line-noise of the language I chose (or had to) to use, and last but not least, when I rename something, I want every single last one of the references to be changed automatically for me, and I don’t want to even consider the slight possibility of having to dig around some XML file or JMock test to finish renaming what the IDE couldn’t find.
I want extended static reflection capabilities: when I tell Spring that every URI that starts with /something needs to go to SomethingController.doSomething(String), I don’t want to give it a method name, I want to give it a reference to the actual method. Likewise, when using JMock I want to write something resembling:
mock.expects(once()).method(Foo.class.instanceMethods.bar(String.class));
instead of:
mock.expects(once()).method("bar").with(isA(String.class));
Even though the former takes a bit more typing, that call to doSomething(String) is something IDEs can work out from the AST without any fiddly string search-and-replace operation.
This feature does not change the syntax of the language (doSomething() would be a call to a method inside some instanceMethods field belonging to Class) and does not introduce any incompatibilities I can think of.
So, why not?

Bob Lee | 26-Sep-06 at 12:09 am | Permalink
Or you could use EasyMock (which has an even cleaner syntax). Being able to reference Method objects more easily would be nice though. Supporting a notion of “thisMethod” would be a good start.
Carlos Villela | 26-Sep-06 at 12:14 am | Permalink
Yeah, EasyMock has a somewhat cleaner syntax, which I currently prefer over JMock’s literate programming style, but that still leaves the configuration for Spring and many other frameworks behind.
I like the idea of thisMethod, but can’t think of any uses for it off the top of my head right now. What do you have in mind?
Diego Pires Plentz » Static reflection | 26-Sep-06 at 12:40 am | Permalink
[...] O Villela recém postou no seu blog, um pequeno recado pro pessoal do JCP, que espero que seja lido, re-lido e repassado até que alguém lá da nave-mãe veja: static reflection. A idéia seria prover alguma forma de reflexão estaticamente, algo do tipo: [...]
Nat | 26-Sep-06 at 1:04 am | Permalink
Have a look at jMock 2: a literate programming style *and* refactoring friendly: http://cvs.jmock.codehaus.org/browse/jmock/jmock2/test/org/jmock/test/acceptance.
Fernando Meyer | 26-Sep-06 at 4:40 am | Permalink
I think you must submit this request. I don’t even know, why sun still use isA?
[trackback] http://fmeyer.org/typo/public/articles/2006/09/26/static-reflection-request
Fernando Meyer’s WebLog » Static reflection request | 29-Sep-06 at 5:14 am | Permalink
[...] Carlos Villela wrote about a new feature request for Java’s reflection API on his blog. [...]
Diego Pires Plentz : Static reflection | 27-Feb-07 at 6:08 am | Permalink
[...] O Villela recém postou no seu blog, um pequeno recado pro pessoal do JCP, que espero que seja lido, re-lido e repassado até que alguém lá da nave-mãe veja: static reflection. A idéia seria prover alguma forma de reflexão estaticamente, algo do tipo: [...]