We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › parsing any number of arguments
Page Index Toggle Pages: 1
parsing any number of arguments (Read 355 times)
parsing any number of arguments
Jan 26th, 2008, 7:37pm
 
I'm trying to build a class similar to an Array (because I need some extra functions). But I read somewhere that the Array is a final class (and cannot be extended).

What would be better: building a class similar to an Array myself, or just extending a Vector?

I've also ran into problems where I wanted a constructor to take multiple parameters. I've read somewhere you can do this like: Code:
class Vec extends Vector {
Vec (float... args) {

But P55 doesn't think so.
Re: parsing any number of arguments
Reply #1 - Jan 26th, 2008, 11:26pm
 
Quote:
What would be better: building a class similar to an Array myself, or just extending a Vector?

It depends on what you need. You may use an java.util.ArrayList maybe? See Java collections (Maps, Lists...) : what you're looking for may exist already.

Quote:
I've also ran into problems where I wanted a constructor to take multiple parameters.

You can pass arrays in constructors, if you want. There's no problem.
Code:
class Vec {
Vec(float[] args) {
}
}
Re: parsing any number of arguments
Reply #2 - Jan 27th, 2008, 11:42am
 
I'm not sure but the "..." syntax may be java 5.0 only (or some non 1.4 version). I've been using that in eclipse no problem, but haven't tried it in pde.

You might be able to force p5 to use 5.0....
Re: parsing any number of arguments
Reply #3 - Jan 27th, 2008, 11:57am
 
What I need is a mathematical vector that has vector functions like size (as in Pythagoras), normalize and a few more. I also want it to be multidimensional, not restricted to two or three.

Yes, I already started to parse an Array into the constructor just to get it working. It would just be nice to be able to use this class like you would with an Array: oInstance[0]. But I guess I'll just have to write a method for getting and setting values.

The class now just has a property: private float[] aVec;. I suspect doing that will be faster than implementing List or Vector: it will be used in something that has a few million iterations.
Page Index Toggle Pages: 1