Return different type of data from a method in java?

前端 未结 13 1511
别那么骄傲
别那么骄傲 2020-12-05 02:18
public static void main(String args[]) {
    myMethod(); // i am calling static method from main()
 }

.

public static ? myMethod(){         


        
13条回答
  •  时光说笑
    2020-12-05 03:13

    you can have the return as an object. You create that object 'on fly' in your

    function: if(int) 
     return new object(){
       int nr=..
    }
    

    same for string. But I am concerned that is an expensive solution...

提交回复
热议问题