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 › problem with casting
Page Index Toggle Pages: 1
problem with casting (Read 606 times)
problem with casting
Dec 19th, 2009, 7:31am
 
hi all

i simpy want a dynamic array with processing ide
array of float

so.. ArrayList object.

is possible that for get a value i had to write:
Code:

ArrayList points;
points = new ArrayList();
points.add(0f);

float theta = ((Float)points.get(index)).floatValue();



otherwise it not compiles..
is it possible?? 1cast and 1 getter and 4 couples of ()..

how can i do it with less syntax? i have to sketch, i can't blow up with thoose syntax problems.. shall i haveto use eclipse for everything?!?

mayebe i'm in wrong.. sorry for my java ignorance..
Re: problem with casting
Reply #1 - Dec 19th, 2009, 9:07am
 
Stay calm!

I'm going to guess this only needs to appear once (maybe twice) in your sketch.

How about a general purpose method - write once, use forever - to do this for you?

Quote:
ArrayList points;

void setup()
{
  points = new ArrayList();
  points.add(1.23f);

  int index = 0;
  
  float theta = getFloat(points, index);
  println("Entry 0: " + theta);
}

float getFloat(ArrayList a, int index)
{
  return ((Float)a.get(index)).floatValue();
}


Perhaps "getFloat" is not the best name (since you want a "float" not a "Float"), but you can use whatever name you like.

-spxl
Re: problem with casting
Reply #2 - Dec 19th, 2009, 9:12am
 
If performance isn't an issue, you can use the handy Array Functions of Processing, they are well suited for bunch of primitive types as they don't need casting back (while I recommend ArrayLists for dynamic lists of objects).
Page Index Toggle Pages: 1