Hello, i want to store some type of Var in the Object, and it cant…
see
Object[] vars = new Object[] { 5, 10.0, true, 20 };
println(vars[0]);
Tell me why ? Or how to make it working… ?
Hello, i want to store some type of Var in the Object, and it cant…
see
Object[] vars = new Object[] { 5, 10.0, true, 20 };
println(vars[0]);
Tell me why ? Or how to make it working… ?
It’s definitely working for me w/ 64-bit PDE 3.5.3 under Win 8.1:
Object[] vars = { 5, 10.0, true, 20 };
println(vars[0]); // 5
println(vars); // 5 10.0 true 20
exit();
WTF, maybe editor gets stuck and tells me bullsh1ts, i open up another new window and it working
How to get Class from objects, thanks <3
Object[] vars = { 5.5, 10.0, true, 20 };
Class[] types = new Class[vars.length];
for (int i = 0; i < vars.length; i++)
types[i] = vars[i].getClass();
for (int i = 0; i < vars.length; i++)
println(types[i].getSimpleName(), vars[i]);
exit();
The output from the code above is:
Float 5.5
Float 10.0
Boolean true
Integer 20
So it is printing the Class of each object. S this not working for you? What is your question?
Also, create a new post for new questions instead of adding questions to this posts.
Kf
BTW, can i append some object to Objects array ?
i try this, but not working
vars = append(vars, new Object[]{22});
vars = (Object[])append(vars, 22);
Ensure you are checking the reference as this is documented there: append() / Reference / Processing.org, quoting:
When using an array of objects, the data returned from the function must be cast to the object array’s data type. For example: SomeClass[] items = (SomeClass[]) append(originalArray, element)
Kf
Thank you !
void setup() {
Prescription test = new Prescription();
test.add("Hello world");
test.add(123.456);
test.add(true);
test.add(5689);
test.add((byte)63);
test.out();
// In the console you can see this list of values that we stored in a Prescription
// String Hello world
// Float 123.456
// Boolean true
// Integer 5689
// Byte 63
exit();
}
class Prescription {
Object[] vars;
Class[] types;
Prescription() {
vars = new Object[0];
}
void add(Object obj) {
vars = (Object[])append(vars, obj);
}
void getClasses() {
types = new Class[vars.length];
for (int i = 0; i < vars.length; i++)
types[i] = vars[i].getClass();
}
void out() {
getClasses();
for (int i = 0; i < vars.length; i++)
println(types[i].getSimpleName(), vars[i]);
}
}