Returning an array without assign to a variable

前端 未结 5 1891
南方客
南方客 2021-01-30 20:24

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         


        
5条回答
  •  感动是毒
    2021-01-30 20:57

    You been to construct the object that the function is returning, the following should solve your issue.

    public int[] getData() {
        return new int[]{a,b,c,d};
    }
    

    hope this helps

提交回复
热议问题