How to get instance of Class with its type parameters

Hi,
Have any of you folks been dealing with generics long enough to show me how this should be written? Or point me to the answer (I have searched as well as I could).
I boiled down my situation to the included sample code, which is long only because of the inserted comments. And while boiling I accidentally came across a surprise solution (a bug?), but would obviously prefer a smoother solution.
My Questions (referred to in the code comments):
#1. Is there a way to get my parameterized type (classarg) without resorting to using the bogus (proto) object?
#2. Can anyone understand why the "C" and "D" attempts are different? (All I did was use an intermediate variable????) Is this a bug?
Thanks so much for any input.
/Mel
class GenericWeird
   /* a generic class -- just an example */
   static class CompoundObject<T1,T2>
      CompoundObject(T1 primaryObject, T2 secondaryObject)
   /* another generic class -- its main point is that its constr requires its type class */
   static class TypedThing<ValueType>
      TypedThing(Class<ValueType> valuetypeclass)
   // here I just try to create a couple of TypedThings
   public static void main(String[] args)
      // take it for granted that I need to instantiate these two objects:
      TypedThing<String>                        stringTypedThing = null;
      TypedThing<CompoundObject<String,String>> stringstringTypedThing = null;
      // To instantiate stringTypedThing is easy...
      stringTypedThing = new TypedThing<String>(String.class);
      // ...but to instantiate stringstringTypedThing is more difficult to call the constructor
      Class<CompoundObject<String,String>> classarg = null;
      // classarg has got to be declared to this type
      //    otherwise there will rightfully be compiler error about the constructor call below
      // This method body illustrates my questions
      classarg = exploringHowToGetTheArg();
      // the constructor call
      stringstringTypedThing = new TypedThing<CompoundObject<String,String>>(classarg);
   } // end main method
   // try compiling this method with only one of A,B,C,D sections uncommented at a time
   private static Class<CompoundObject<String,String>> exploringHowToGetTheArg()
      Class<CompoundObject<String,String>> classarg = null;
      /* Exhibit A: */
  ////     classarg = CompoundObject.class;
         results in compiler error "incompatible types"
         found   : java.lang.Class<GenericWeird.CompoundObject>
         required: java.lang.Class<GenericWeird.CompoundObject<java.lang.String,java.lang.String>>
               classarg = CompoundObject.class;
                                        ^
         I understand this.  But how to get the type information?
      /* It's obnoxious, but it looks like I will have to construct a temporary
          prototype instance of type
             CompoundObject<String,String>
          in order to get an instance of
             Class<CompoundObject<String,String>>
          (see my Question #1) */
      CompoundObject<String,String> proto = new CompoundObject<String,String>("foo", "fum");
      /* Exhibit B: */
  ////     classarg = proto.getClass();
         results in compiler error: "incompatible types"
         found   : java.lang.Class<capture of ? extends GenericWeird.CompoundObject>
         required: java.lang.Class<GenericWeird.CompoundObject<java.lang.String,java.lang.String>>
               classarg = proto.getClass();
                                        ^
      /* Exhibit C: */
  ////     classarg = proto.getClass().asSubclass(proto.getClass());
         results in compiler error: "incompatible types"
         found   : java.lang.Class<capture of ? extends capture of ? extends GenericWeird.CompoundObject>
         required: java.lang.Class<GenericWeird.CompoundObject<java.lang.String,java.lang.String>>
               classarg = proto.getClass().asSubclass(proto.getClass());
                                                     ^
      /* Exhibit D: (notice the similarity to C!): */
  ////     Class tmp1 = proto.getClass();
  ////     classarg = tmp1.asSubclass(tmp1);
      /* It compiles (see my Question #2) */
      return classarg;
   } // end method exploringHowToGetTheArg()
} // end class GenericWeird

Thanks so much, Bruce. (Oh my goodness, how would I have ever come up with that on my own?)
So in summary
This doesn't compile:
      classarg = (Class<CompoundObject<String,String>>)CompoundObject.class;but these do compile:
      classarg = (Class<CompoundObject<String,String>>)(Class)CompoundObject.class;or
      Class coclass = (Class)CompoundObject.class;
      classarg = (Class<CompoundObject<String,String>>)coclass;And this doesn't compile:
       classarg = proto.getClass().asSubclass(proto.getClass());but this does:
       Class tmp1 = proto.getClass();
       classarg = tmp1.asSubclass(tmp1);

Similar Messages

  • How can I copy test plan WITH ITS RESULTS (PASS/FAIL) to other project in MTM??

    How can I copy test plan WITH ITS RESULTS (PASS/FAIL) to other project in MTM??

    Hi odedn,
    Thank you for posting in MSDN forum.
    Based on your issue, you mean that you want to copy the test plan with test results from the current team project
    to other team project, am I right?
    If yes, as far as I know that when we copy test plan with test results to other team proejcts. It is default that
    there just will not copy the test plan with test results (pass/fail) to other team project in MTM.
    You can refer the following MSDN document’s
    what gets cloned, it explained that which objects are copied from the source test plan to the destination test plan.
    Reference:
    http://msdn.microsoft.com/en-us/library/hh543843.aspx
    If you still want to this feature, I suggest you can
    submit this feature request:
    http://visualstudio.uservoice.com/forums/121579-visual-studio. The Visual Studio product team is listening to user voice there. You can send your idea there and people can vote. If
    you submit this suggestion, I hope you could post that link here, I will help you vote it.
    Thanks for your understanding.
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to get SDKODBC Wrapper class for indesign cs3

    Hi,
         I have to implement the mysql database with my indesign plugin. I didn't have a SDKODBC Wrapper class. Can any one say how to get SDKODBC Wrapper class from adobe.
    Regards,
    saravanan.

    I doubt if change documents are generated for SE78 transaction.
    For list of change documents defined, please check table: TCDOB.
    Hope this helps.
    Kind Regards
    Eswar

  • How to get Portal Login User and Its Related BP in CRM?

    Hi,
    An ABAP Webdynpro program is called in CRM from Portal user by a portal link. How to get the user ID and its related BP in CRM? Thanks!
    The portal is integrated with ECC, and all users and BPs are maintained in ECC then replicated to CRM.
    Best regards,
    Hao

    Hi,
    Try the below code
    IUserFactory userfact=UMFactory.getUserFactory();
    IUser user=userfact.getUserByUniqueName(request.getUser().getUserId());
    String usrid=user.getUniqueName();
    And also you can get the groups assigned to user by using the below code
    Iterator groups = user.getParentGroups(true);
    while (groups.hasNext()) {
         String groupstr = (String) groups.next();
         IGroup g = UMFactory.getGroupFactory().getGroup(groupstr);
         response.write("Group name "g.getUniqueName()"<br>");
    Regards
    Suresh

  • Re: How to create More two class with one object

    haii,
             i have small information How to create More two class with one object,
    bye
    bye
    babu

    Hello
    I assume you want to create multiple instance of your class.
    Assuming that you class is NOT a singleton then simply repeat the CREATE OBJECT statement as many times as you need.
    TYPES: begin of ty_s_class.
    TYPES: instance   TYPE REF TO zcl_myclass.
    TYPES: end of ty_s_class.
    DATA:
      lt_itab      TYPE STANDARD TABLE OF ty_s_class
                     WITH DEFAULT KEY,
      ls_record  TYPE ty_s_class.
      DO 10 TIMES.
        CLEAR: ls_record-instance.
        CREATE OBJECT ls_record-instance.
        APPEND ls_record TO lt_itab.
      ENDDO.
    Regards
      Uwe

  • Has anyone figured out how to get speech recognition working with sticky keys enabled on mountain lion?

    I'm trying to use speech recognition to input text on my iMac running the latest mountain lion, 10.8.3.
    I have sticky keys enabled.
    When I try to start speaking by pressing the function key twice nothing happens. I can only get it to work if I disable sticky keys.
    The same problem occurs with all the other modifier keys as shortcut, they do not work with sticky keys.
    When I try to select a different shortcut, I am unable to select a two key combination, but am limited to one.
    If I select the F6 key, or any other single key, I am able to start speech recognition. However the second time that I press the key, it does not stop recognition and process my words. Instead, it restarts the recognition.
    Has anyone figured out how to get speech recognition working with sticky keys enabled?
    Or a way to get an individual key shortcut to start on the first press and process it on the second?
    Or a way to get key combinations to work, as specified by the help:
    Dictation On and Off
    To use Dictation, click On.
    When you’re ready to dictate text, place the insertion point where you want the dictated text to appear and press the Fn (function) key twice. When you see the lighted microphone icon and hear a beep, the microphone is ready for you to speak your text.
    Shortcut
    By default, you press the Fn (Function) key twice to start dictation. If you like, you can choose a different shortcut from the menu.
    To create a shortcut that’s not in the list, choose Customize, and then press the keys you want to use. You can press two or more keys to create your shortcut.

    I noticed with version 10.8.4 of OS X that I am now able to select F6 to activate, and the return key to complete the speech recognition. This is still different than the description of how these should function that's included in the help, but at least it's an improvement.

  • How to get the object class field value in CDHDR table for vendor

    hi
    how to get the object class field value in CDHDR table for vendor

    Try KRED/KRED_N as object class in CDHDR for Vendor.

  • How to get gui_download and gui_upload with popup filename?

    how to get gui_download and gui_upload with popup filename?

    Here is a short example.
    report zrich_0003 .
    data: ifiletab type filetable.
    data: xfiletab like line of ifiletab.
    data: xstring type string.
    data: rc type i.
    data: itab type table of string.
    data: xtab type string.
    start-of-selection.
      call method cl_gui_frontend_services=>file_open_dialog
        changing
          file_table              = ifiletab
          rc                      = rc.
      read table ifiletab into xfiletab index 1.
      xstring = xfiletab-filename.
      check not xstring is initial.
      call method cl_gui_frontend_services=>gui_upload
        exporting
          filename                = xstring
      changing
        data_tab                = itab.
      loop at itab into xtab.
        write:/ xtab.
      endloop.
    Regards,
    Rich Heilman

  • How to get the contents associated with a component.

    How to get the contents associated with a component.
    Like i have 2 buttons and i want to get the contents associated with these button without clicking them i.e without firing the event.
    By Contents i mean, whatever things we get after firing the event,we get some other window and some thing is added to the current page and so on.

    grab all the code inside the actionPerformed(ActionEvent e) method

  • How to get a minus sign with the cost  field in ALV.

    Hi ,
    How to get a minus sign with the cost field in ALV.
    The Ouput will be displayed like  Rs -1500 instead of 1500-
    I can't use concatenate also as i may have to use the sum functionality of ALV .
    Cheers
    Sunny

    Hi sunny,
    1. The OTHER FIELD
       has to be character field of say length 15.
    2. Write the original numeric value to
       this character field (in a loop)
    3. But simply writing won't help.
    4. use this kind of logic.
    5.
    REPORT abc.
    DATA : m TYPE i.
    DATA : chr(15) TYPE c.
    m = -100.
    WRITE m TO chr.
    IF m < 0.
      SHIFT chr RIGHT BY 1 PLACES.
      CONDENSE chr.
      CONCATENATE '-' chr INTO chr.
    ENDIF.
    WRITE chr.
    regards,
    amit m.

  • Query to get value sets associated with its descriptive flexfield

    Hi All,
    Here i have a issue
    I am trying to get Value sets associated with its descriptive flex field of Receivable application and
    also if i want this for particular responsibility i.e., GW RBC Receivable Super User.
    I hope u got it.
    Please suggest me some query to get this.
    This is very important for me.

    Hi, I think your question should be addressed to the OEBS experts

  • How to get vlan tag programe with mac book air

    how to get vlan tag programe with mac book air,i'm using the usb ethernet adapter

    For prompt help contact TATA.
    For more on this: https://discussions.apple.com/thread/3680625?tstart=270

  • How to get an error icon with tool tip in a displaying table   in a particu

    How to get an error icon with tool tip in a displaying table   in a particular field..
    Thanks.

    Hi,
    In the context  create an attribute of type string .
    Create the attribute in the node which you bind for table.
    In the layout .
    1.create a Table UI element.
    2 create binding for UI element.
    3Right click on the Table UI and select insert table column.
    4.once the table column is inserted right click on table column and select insert cell editor.
    5.create the cell editor of the type image.
    6.Bind the source property of the image to the attribute in the node which you have created.
    so depending on what image(type of icon) needs to be displayed set the attibute accordingly.
    refer to the link for image :
    [http://help.sap.com/saphelp_nw70ehp1/helpdata/en/d1/af8841349e1909e10000000a155106/frameset.htm]
    Priya

  • When I'm on an app, on iso7.1 it will now show the "iPad/iphone" sign the time and the battery whilst running in an app. does anyone know how to get rid of that as its effecting the games i play.

    when I'm on an app, on iso7.1 it will now show the "iPad/iphone" sign - the time - and the battery whilst running in an app. does anyone know how to get rid of that as its effecting the games i play.

    If you can hide the status bar, it would be an option inside the app. I have one or two apps where that is an option but in most apps it is not.

  • How to get the values from struct data type using java code..?

    Hi ,
    I am newer to java.
    we are using oracle database.
    How to get the data from struct data type using java code.
    Thanks in Advance.
    Regards,
    kumar

    Hi Rajeev,
    To retrieve a FilterContainer you will need to traverse the report structure:
    ReportStructure boReportStructure = boDocumentInstance.getStructure();
    ReportContainer boReportContainer = (ReportContainer) boReportStructure.getReportElement(0);
    FilterContainer boFilterContainer = null;
    if (boReportContainer.hasFilter()) {
         boFilterContainer = boReportContainer.getFilter();
    } else {
         boFilterContainer = boReportContainer.createFilter(LogicalOperator.AND);
    Calling boDocumentInstance.getStructure() will retrieve the entire structure for the document.
    Calling boReportStructure.getReportElement(0) will retrieve the structure for the first report of the document.
    Hope this helps.
    Regards,
    Dan

Maybe you are looking for

  • Flickering in clips when brightness/contrast adjustments applied

    In CS3 I apply brightness and contrast changes to a clip.  When I view that clip in the preview monitor, and also when I view that clip after exporting to DVD on a television, there are intermittent random quick changes in the brightness.  Screen app

  • Update rules infocube 0py_c02 not found BI 7.0

    Hello Forum, By activating the infocube standard payroll (0PY_C02), I found the problem that the rules for updating the infocube not exist and neither are activated in the BI content version 7.0. I have written a note to Sap, and I say it is not a mi

  • Error message HP Device Monitor quit unexpectedly will not go away! Help please.

    Hi, I deleted our old HP Printer from MAC and loaded the new one. Now I'm getting an error message constantly. Sending report, Ignoring, Relaunch - nothing gets rid of it. Also rebooted computer, turned it off, and unplugged new printer all to no ava

  • Animation while page loading

    I just created an animation using fireworks that according to the tutorial can be used as animation while the page is loading. What format does this file need to be in and where should i upload it on the server ...(anyone have a tutorial)...the one i

  • Name attribute now showing in layer

    Hi, I am very new to After Effects scripting, but have been programming in C++ for about 25 years, so I have a programming background.  I am creating a camera rig script.  In the script I create a null and want to name it "Camera Control".  I am usin