What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 131 Stack Exchange communities.

What is method by reflection in Java reflection API?

While the wording of this question may not have been the greatest (I wasn't given a chance to edit it, since I was busy answering... :-P), the content is quite valid.

Before JDK 1.6 the only ways to dynamically access a given class instance were the reflection API and byte code compilation. Reflection is slow, byte code compilation is complex.

In 1.6 we gained the ability to put Java source code in a string and compile it dynamically. This performs significantly better than reflection (30% in our tests), and the method is not entirely obvious.

So, as the question asked, "what can I use besides reflection", and given that we had asked ourselves the exact same question a few weeks ago, I had a valid answer to what was to me a very specific question. In fact, I was able to post a source code example, which to me indicates that the question was specific enough.

Now, I can't vote to reopen, or I would. But my opinion and suggestion is that this question be reopened.

share|improve this question
I was one of the people who voted to close. As is, in my opinion, the question is lacking: what can you use besides reflection to do what? I have no idea if dynamic class compilation has anything to do with what the user who posted that question wants. –  Mat Nov 18 '11 at 15:14
@Mat English is, I think, not the OP's first language, and the question is definitely hard to understand, but to me the question was somewhat obvious: how do I call a method dynamically without using reflection? At any rate, even if it is just the more open-ended "what can I use besides reflection" then it can be interpreted as "what can I use besides reflection to do the sorts of things that reflection does", which I think is a very valid question as well. –  Scott A Nov 18 '11 at 15:41

1 Answer 1

Let's play my favorite game: The FAQ-Test:

  • a specific programming problem ➔ Not a specific one, nope
  • a software algorithm ➔ No
  • software tools commonly used by programmers ➔ No
  • practical, answerable problems that are unique to the programming profession ➔ Uuhh...kind of, maybe...

That's 0.5/0.5 out of 4.

Additionally...that question is poor. It's like asking:

  • What ways are there to increment a number by 1 except ++?
  • How can I read a file without using a stream?
  • Are the other methods instead of static to create a static variable?

And the last sentence is pretty much the final nail in the coffin: A source code example will be helpful.

share|improve this answer
Specific programming problem: how do I call a method dynamically without using the Reflection API? Software tools commonly used by programmers: reflection, byte code compilation, and now dynamic compilation are most definitely tools used by Java programmers. And given that I just had this problem a few weeks ago, I don't see how it could not be considered practical. –  Scott A Nov 18 '11 at 15:40
Incidentally, I think the subject matter of the question is significantly more complex than incrementing a number, given the performance and complexity considerations that go into the decision of whether to use reflection or not. –  Scott A Nov 18 '11 at 15:51
@ScottA: You can interpret into that question all kind of stuff. That's why it's closed. –  Time Traveling Bobby Nov 18 '11 at 15:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .