Passing as a parameter, an object + another variable
I'm have trouble an object which has three integer values in it along with another parameter which is simply a double. This is my syntax atm:
Code :
Object newObject = new Object((1,-2,35),.5);
I'm not sure how this is supposed to be written out in order for the object to accept it. Thank you in advance for any assistance you may provide!
Re: Passing as a parameter, an object + another variable
No, you cannot have nested parenthesis like that. Perhaps all you need to do is to remove the inner nested parenthesis and this will work. The key will be to inspect the constructors available for this class and to call one of them appropriately. By the way, hopefully your class is not named "Object", right?
Re: Passing as a parameter, an object + another variable
Nah it isnt called object, im just generalizing the statement...but i checked out the constructor and it seems to be in the correct order and the parenthesis idea didnt work :(
Re: Passing as a parameter, an object + another variable
Um.... care to share the constructor with us?
Re: Passing as a parameter, an object + another variable
Code :
public class Object {
private Coord3D origin;
private double intensity; // In range [0..1]
public Light (Coord3D origin, double intensity) {
this.origin = origin;
this.intensity = intensity;
}
Re: Passing as a parameter, an object + another variable
Wouldn't it just be:
Light light = new Light(new Coord3D(object), 5);
??
Re: Passing as a parameter, an object + another variable
Indeed you would need to pass a Coord3D object into the Light constructor, likely
Code :
Light light = new Light(new Coord3D(1, -2, 35), 0.5);
Or something similar.