2 Replies Latest reply on Jun 22, 2010 4:41 PM by forumKid2

    One method that can return different types

      I have a method that does some processing and can return a resultset or string or int.

      Right now I have the method like this (example mockup as I know this exact code makes no sense)
      public Object getData(int i){
      Object o;
      if(i == 1){
       ResultSet rs = null;
       o = rs;
      } else if(i == 2){
       String s = "myString";
       o = s;
      return Object;
      So this works fine. It returns a resultset or string based on the input parameter.

      My calling class can cast and get the data just fine.

      My question here, is there a better way using generics and wildcards to return a type that is not known at compile time?