[SOLVED] Easiest way to call 100 instances of an object?

Discussion in 'Spigot Plugin Development' started by MrEminent42, May 17, 2015.

  1. I am coding a plugin (not relevent), and all I need to do is call 100 instances of an object. Is there a way to do that without writing new foo(m); 100 times? And there is no name for the instance so I don't need it to be public.

    Could I do something like this?
    Code (Java):
    for (double m = 1.0; m < 10.1; m++ ) {
      new foo(m);
    }
     
  2. Increment an integer.
     
    • Agree Agree x 1
  3. Right, but would I use a for() loop? Or is there something else I should use?
     
  4. Any kind of loop will suffice.
     
  5. Ok thanks :)
     
  6. I can also do it with a Double, right? Just add 0.1 (Need it for my plugin)?
     
  7. Use an int. There is no reason to be using doubles, and especially not its wrapper class.
     
  8. Well because I have to call instances that has a parameter that increases by 0.1 every time.
     
  9. divide by 10.
     
  10. Oh ok :p
     
  11. make sure to cast the int to a double before dividing or it will end up rounded.
     
  12. xD Thanks :)

    And when you say rounded, do you mean it will really round to the nearest whole or will it just chop off the decimal?
     
  13. Chop off the decimal