vendredi 29 mai 2015

What instance of the Object is this method returning?

I have written a below method but I need to find the instance of object returned.Also I need to check if it is a JSON type or other type returned then will this method work?

public class DynamicObject {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        DynamicObject obj = new DynamicObject();

        if(obj.testObj() instanceof String)
            System.out.println("String");
        else if (obj.testObj() instanceof Array)
            System.out.println("Integer Array");
        else if (obj.testObj() instanceof Integer)
            System.out.println("Integer");


    }

    private Object testObj(){
        boolean test = false;
        String s= new String("test");
        Integer in[] = {1,2,3,4,5};
        if(test){
            return s;
        }else{
            return in;
        }
    }

}

What shall be the instance of this case.If I run this then console doesn't show anything.





Aucun commentaire:

Enregistrer un commentaire