0

I want to do something like this:

for(int i = 0; i<5;i++)
    {
        public void test[i]()
        {
            System.out.println(i);
        }   
    }

Can I even create methods like this? I know it requires an array but I have read everywhere about method arrays and it doesn't do it like I want it to.

I don't want to make several methods and then save them in an array, I want to create methods in a loop, and I don't know how to do this.

I need it so I can make as many methods I want of this certain method, instead of writing 100 methods.

10
  • Err no idea what you're trying to do. Commented Oct 26, 2012 at 10:04
  • 1
    First of all you cannot create even a normal method in a loop like that. Secondly you need to be more specific, what exactly you want to do. Keep aside the method for a while. Commented Oct 26, 2012 at 10:05
  • Why create duplicate method? I think its not possible in Java. You can call the same method several times. Commented Oct 26, 2012 at 10:05
  • And how do you intend to call these methods you're creating? Commented Oct 26, 2012 at 10:06
  • Why can't you just remove that method, and just let the sysout do its work? Commented Oct 26, 2012 at 10:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.