Is there any way in java to return a new array without assigning it first to a variable? Here is an example:
public class Data {
private int a;
private i
You still need to create the array, even if you do not assign it to a variable. Try this:
public int[] getData() {
return new int[] {a,b,c,d};
}
Your code sample did not work because the compiler, for one thing, still needs to know what type you are attempting to create via static initialization {}
.