Get the Type of a generic field at runtime, How to?

Hello,
As the topic already says, i need to get the Type of a particular field of a class. This field is declared private and generic. In C# there is a method
Type Object.getTypeIs there any specific way to do this in Java 1.5?
Please excuse my poor english.
Thanks in advance.
Markus

McNepp wrote:
endasil wrote:
McNepp wrote:
If you want to know the parametrized type (String in the example), I think there is no way of knowing this in Java 1.5 or Java 1.6, since the parametrized type is erased and not available at run time.The type of a parameterized field is not erased.For most intents and purposes, it is. Type erasure refers to the fact that at runtime, there are not actually multiple class binaries depending on the generic arguments to a class. Therefore, an ArrayList<T> is actually just an ArrayList with no generics.
Frankly, I don't understand why you insist that the information on generic fields that the OP was asking about is lost at runtime.I wasn't trying to insist that. At the time, I was replying more to Saish and trying to reaffirm that most information about generics is lost at run-time. I mistakenly ignored how you qualified it with "field."
What you write about instances of generic classes losing their type information is of course correct, albeit not to the point of the original question.Nope, you're right. I was just trying to reconcile the fact that many people get confused that there's any information available at run-time, and so start down the path of thinking that type erasure doesn't exist. But it very much does.
The original question was about how to obtain the type of a generic field.And I did show in my example that even that is fairly limited, given that if the type is provided by the parameter of the class, it doesn't give you anything useful (I'm not trying to say you said it would!).
The compiler preservers this information in the class file, so it can be obtained at runtime. Frameworks like JPA put this to use extensively, proving that it is of real value.Definitely. However I don't see this having as much to do with generics as basic reflection functionality. If you can get the type of a field at run-time, you should be able to get the parameters as well! That should in no way belittle its value, though. But I would have guessed (knowing little about) that JPA wouldn't put that to use so much as the type parameters of an accessor return type or mutator argument type. Especially since I thought we'd shown that you would need your fields to be non-private for JPA to be able to gain information about their type.
Edit: getDeclaredField works fine with private members, and returns the expected "java.lang.String" from jschell's example above
Edited by: endasil on 28-Apr-2009 10:39 AM

Similar Messages

  • How to get the width of a numeric field at runtime

    Hi, everyone :D
    Is there a built-in that let me get the width of a numeric field at runtime? The SRW bulit in only has the SWR.GET_PAGE_NUM built-in. Is there something like the Get_item_property of Forms IN Report?
    Thanks
    Edited by: user12422762 on 07-ene-2010 14:16
    Edited by: user12422762 on 07-ene-2010 14:30
    Edited by: user12422762 on 08-ene-2010 4:40
    Edited by: user12422762 on 08-ene-2010 4:50

    Hi. Thanks for answering. I need the width because i want to set the format of the field at runtime. The quantity of decimal digits for all the numeric fieds in the report is received as a parameter.
    I can use a function to create the respective decimal mask ('D99,'D999',etc.) and then call the SRW.SET_FORMAT_MASK in the format trigger of every single field, but i'd have to type the mask of the integral part of the number in the code of the trigger ('99G999D99, '999G999G999D'). However, If i could get the width, i'd just create a function and call it from every format trigger.
    Edited by: user12422762 on 08-ene-2010 10:05
    Edited by: user12422762 on 08-ene-2010 10:06
    Edited by: user12422762 on 08-ene-2010 10:08

  • How to get the type of answer in a workitem?

    Hi Experts,
    I am building a report to get the users responsible for the approval of SCs and POs, in this report I need to get the type of answer given by the approver, if they have rejected, approved or partial rejected / approved the object.
    When I look at the container of the workitem I can get the agent responsible for the action and the dates, but I need your help to determine the type of answer. I believe I can get this information from the approval state, no? But I am getting a lot of different approval states: 0, 1, 3, 4, 10, 11 and 15. Can you provide me some guidance? I am new to workflows and I am stuck in this point.
    I am using SRM 5.0 and n-step approval workflow.
    Thanks in advance,
    Francisco

    I'm not an SRM expert, but from a pure workflow point you can read the output of a workitem. So, check how your workflow is built and then see what values are returned in the corresponding return fields. Explore the workitem structure in the log.

  • How to dynamically get the SOM expression of a field?

    As a follow up to the note below, I would really appreciate any help as of how to get the SOM expression of a field dynamically, by this, I mean how to get the SOM expression of a field at running time using JavaScript.
    Thanks,
    Isis
    That does make things clearer.  You will have to save the change  information in the XML.  I realize that you don't want to save an xml  node for every field, but there is a better way.  You can use scripting  to add data nodes to the XML data in the form.  I'm thinking of the  following:
    Include an empty container node in your XML schema: <HighlightedFields></HighlightedFields>
    When  a field is changed, in the field's change event call a common script:  HighlightChangedField, passing in the object.  The script will highlight  the field (set the border a certain color or whatever).  It will also  add node underneath the HighlightedFields data node with the SOM  expression of the field.  The SOM expression is the "path" of the object  in the form heirarchy, sort of like an xpath.  So if you have a subform  named Subform1 and you change the Name and Address textfields, you  might end up with something like:
    <HighlightedFields>
        <HighlightedField>
            <SOMExpression>xfa[0].form[0].myform[0].Subform1[0].Name[0]</SOMExpre ssion>
         </HighlightedField>
        <HighlightedField>
            <SOMExpression>xfa[0].form[0].myform[0].Subform1[0].Address[0]</SOMEx pression>
         </HighlightedField>
    </HighlighedFields>
    The  upside of this is that you only store XML nodes for what is changed  instead of needing a specific XML node for each field.  The downside is  that you will need a call to the common script in every field's change  event: HighlightChangedField(this);
    Now, to make this work  when a form is loaded the next time, in the initialize event at the  topmost subform in the hierarchy you add a script that walks the  HighlightedFields data node, and for each HighlighedField entry you  highlight the contained object.  You can get a reference to an object  using its SOM expression, so just take the SOM expression from each  entry and do an xfa.resolveNode(SOMExpression) to get the object, then set whatever attributes you want to highlight the field.
    The  big issue I see with this would be if you have dynamically added  objects on your form.  In that case you would probably need to store the  instance index along with the SOM expression for each changed object,  then use that instance number when highlighting on form load.

    As a follow-up, I had said I would try to put together an example for you.  The setting of the change indications and the highlighting of the fields is not a problem, but I did have an issue that perhaps one of the experts on the forum can help with:
    The problem is how to detect a change in a text field without a lot of overhead.  You can't just place a call to the highlight method in the Exit event without checking for a change, since the user can just tab from field to field without changing anything. Unfortunately the properties that show the old text and new text of a field are not valid on the Exit event.  An alternative is to use the Change event, but with a text field the event fires for every character typed.  This seems like a lot of extra processing..
    Anyone know a better way?  I went as far as using the extras collection on fields to hold the last value, but that adds a lot of complexity since it needs to be set to the initial raw value when the form is first loaded. I'd like to find a solution that doesn't require a lot of code to be added to every field on the form.

  • How to get the type of numeric

    Hi,
    I would like to know how getting the type of a numeric data programmatically. (DBL, SDL, I16, I32,etc.)
    This property is defined by selecting "Type of data" in the property's window of a numeric data; then by clicking on "representing".
    I tried to find the solution by using a property node then accessing to the property called 'representing".
    Without success, it seems this function is not available.
    Is anyone would know the solution.
    Thanks by advance,
    pr93

    There are several solutions.
    The 7.x version of the Flatten To String function had an additional output called "type string" which was actually an array of numbers. This array would tell you that information. OpenG has a VI that will tell you the datatype from this array. It's called "Get TDEnum From TD" and is in the LabVIEW Data Tools library. You can use VI Package Manager to easily install OpenG libraries.
    If you have a control you could use a reference and then use the "Get Type of Control" VI from the <vi.lib>\Utility\GetType.llb library.
    You could convert th"e numeric value to a variant and then use the "Get Type of Variant" VI from the <vi.lib>\Utility\GetType.llb library.

  • I need to get the value of a text field that is located in another page JSP

    I need to get the value of a text field that is located in another page JSP. How do I do that?

    Well you see, I have a page at angelfire.com, which
    does not support JSP. I want to call a script located
    at mycgisever and then, when pressing a link on the
    former page, the JSP page is loaded, and the script
    get the value from the text field on the OTHER page.
    Is this possible?I know nothing about cgi. But that should not prevent me from understanding what can and cannot be done, assuming cgi is sort of comparable with jsps.
    I'm unable to understand your description clearly. Try to explain it better. Give precise steps that you intend to follow and I should be able to help you further.
    So you have a page1.
    You hit submit from page1.
    That goes to the cgiserver.
    From the cgiserver, programmatically load up the jsp.
    search this for the text field.
    Display it on your page2.
    Is that what you are trying to do?
    BTW, won't be able to help you with cgi scripting at all. Can help with Java and Jsp.

  • Get the type of collecion elements

    Hi,
    I would like to get the type of the elements of a collection when I give the name the collection. Does anybody suggest anything about the SQL code?
    For example
    CREATE OR REPLACE TYPE CourseList AS TABLE OF VARCHAR2(64);
    CREATE TABLE department (
    name VARCHAR2(20),
    director VARCHAR2(20),
    office VARCHAR2(20),
    courses CourseList)
    NESTED TABLE courses STORE AS courses_tab;
    How it is possible to get the type of elements of CourseList (in the example it is VARCHAR2(64)) if I give the name of the nested table courses?
    Thank you

    > I would like to get the type of the elements of a collection when I give the name the collection.
    sniff sniff
    Smells like some kind of dynamic SQL or dynamic PL/SQL thing. It usually stinks.
    If the dynamic part comes into play at rendering time (like in APEX for example that executes a SQL and then needs to dynamically render the projection) - use DBMS_SQL cursors (or ref cursors when rendering in an external client). Use the describe interface to dynamically determine the structure of the SQL projection.
    Anything more than that - think carefully. Especially at it seems you want to deal with actual relational data structure dynamically. 99% of the time it is flawed and the remaining 1% of the time the person usually have no idea what he (or she) is really doing... ;-)

  • Get the Type (U8, U16...I64) of controls inside a Cluster

    Hi,
    I have a cluster with several controls. 
    I would like to get the type of each control inside of it. To get the class is ok. This is simple and all of them are Digital. But I need to know if they are U8, U16, U32 ...... I64. 
    Any idea how to do this?
    Paul
    Solved!
    Go to Solution.

    I got it.
    I had to Convert the Element Refernce to Digital and then to use the property BitAccurateDataSize.
    I lost several hours to find the solution and in 5 minutes after I had posted my problem on forum I solved it . 

  • Every time I try to upload MOV files from my iphone 5s onto my adobe premiere elements on windows 8 i get 'the importer reported a generic error'

    every time I try to upload MOV files from my iphone 5s onto my adobe premiere elements on windows 8 i get 'the importer reported a generic error'

    jade harding
    What version of Premiere Elements are you using on Windows 8.1 64 bit? For now I will assume Premiere Elements 12 in a NTSC set up.
    Your iPhone 5s video is expected to be 1080p @ 30 progressive frames per second? Do you confirm that? Because of the source of your video, it is highly likely that you are dealing with a variable frame rate.
    Please give the following a try to see if you then have an "importable" product to take into Premiere Elements presumed 12/12.1.
    Download and install the free HandBrake program.
    http://handbrake.fr/
    Import your video file into the program.
    Make sure you browse to and set Destination (suggested Desktop location)
    Go to the Video Tab and set
    Video codec = H.264 (x264)
    Frame Rate = 29.97
    put a dot next to Constant for the Frame Rate
    Click on the Start at the top left of the workspace
    Wait for the "Queue Finished" to appear in the progress bar at the bottom left of the workspace.
    Then see if this H.264.mp4 (1920 x 1080 @ 29.97 progressive frames per second file can be imported into Premiere Elements 12 project with a manually set project preset of NTSC/DSLR/1080p/DLSR 1080p30@ 29.97.
    Details for setting manual project preset can be found in
    ATR Premiere Elements Troubleshooting: PE11: Accuracy of Automatic Project Preset (New Project Dialog) Setting
    The details that I have posted in this reply are customized for Premiere Elements and should work fine for you.
    We will be watching for your results.
    ATR

  • How to get the type of org.omg.CORBA.Any ?

    Hi there
    My q is: how can I get the type of an Any object?
    Please have a look at the following code:
    ORB orb = ORB.init();
    org.omg.CORBA.Any anytest = orb.create_any();
    anytest.insert_string("mystring");
    TypeCode tc = anytest.type();
    Now how can I get back that the type is String??
    Regards
    Brian

    Hi,
    Try using anytest.type().kind().value() -> should yield TCKind._tk_string. See the javadoc for more info.
    I think that the only way to check types is by comparing the codes; as far as I know there is no easy way to get the equivalent Java Class object or so. But I could be wrong on that one.
    Best,
    Guy

  • JAXB:How to get the type of an element

    Hi
    I am working with JAXB 2and i am using a custom ValidationEventHandler to validate my xml document:The issue I have is that when my document isn't valid,i would like to get the error node and its type(string,date...)
    I tryed node.getNodeType() but it return if the node is ATTRIBUTE_NODE,TEXT_NODE....
    public boolean handleEvent(ValidationEvent ve) {           
            if (ve.getSeverity()==ValidationEvent.FATAL_ERROR || 
                                   ve .getSeverity()==ValidationEvent.ERROR){
                ValidationEventLocator  locator = ve.getLocator();
                org.w3c.dom.Node node=locator.getNode();
              System.out.println("ERROR element type:"+node.getNodeType());
             return true;
           }How could i get the type(String,Date,Integer...) of the node in error?
    Edited by: riadhhwajdii on Aug 14, 2010 4:20 AM

    As you already mention that is not resolved before the annotation processing stage
    [ http://openjdk.java.net/groups/compiler/doc/compilation-overview/index.html]
    So, you probably need to produce your own analysis code or better reuse the compiler's own code if that turns out to be easy (no clue). I reckon it is better if you avoid modifying the compiler itself as it will make much more difficult to maintain and deploy your (more than a) processor.
    Sorry if you already tough about this.
    Edited by: discretoboy on Apr 7, 2009 3:20 PM

  • I updated the IPAD with the latest update and now when I turned the IPAD on, I get the itunes logo and then nothing else.  How can I fix this to let me use my IPAD?

    I updated the IPAD with the latest update and now when I turned the IPAD on, I get the itunes logo and then nothing else.  How can I fix this to let me use my IPAD?

    YOU ARE IN RECOVERY MODE
    1. Turn off iPad
    2. Turn on computer and launch iTunes (make sure you have the latest version of iTune)
    3. Plug USB cable into computer's USB port
    4. Hold Home button down and plug the other end of cable into docking port.
    DO NOT RELEASE BUTTON until you see picture of iTunes and plug
    5. Release Home button.
    ON COMPUTER
    6. iTunes has detected iPad in recovery mode. You must restore this iPad before it can be used with iTunes.
    7. Select "Restore iPad"...
    Note:
    1. Data will be lost if you do not have backup
    2. You must follow step 1 to step 4 VERY CLOSELY.
    3. Repeat the process if necessary.

  • I am trying to connect my Sony DCR-TRV350 to iMovie so that I can make DVD's from family videos.  I am having problems getting the video camera connected.  Any advice on how to do this?

    I am trying to connect my Sony DCR-TRV350 to iMovie so that I can make DVD's from family videos.  I am having problems getting the video camera connected.  Any advice on how to do this?

    What happens when, after you connect your cam, you go to File > Import Media?
    But before that, does your cam require you to export your video files upon USB connection? I have a JVC Everio HD and I have to "Export to Library" from the cam's menu first-thing. This was true even in prior iMovie versions.

  • My iPad conveys that it is disabled, and that I need to connect to iTunes.  When I connect to iTunes I get a message that I need to enter my pass code and open my Ipad, but I don't get the screen to open with a password.  How do I fix this?

    My iPad conveys that it is disabled, and that I need to connect to iTunes.  When I connect to iTunes I get a message that I need to enter my pass code and open my Ipad, but I don't get the screen to open with a password.  How do I fix this?

    You will need to restore it. It may not sync, but the iPad's sidebar has to appear you can restore it and it will be as the last time ou synced it to iTunes. For more info:
    iTunes: Backing up, updating, and restoring your iPhone, iPad, or iPod touch software

  • When I click on my Yahoo bookmarks, I only get the download Yahoo toolbar page, I downloaded the toolbar again and I still get the same page when I hit bookmark icon - how do I get my bookmarks back - they still show on Microsoft Explorer

    Question
    When I click on my Yahoo bookmarks, I only get the download Yahoo toolbar page, I downloaded the toolbar again and I still get the same page when I hit bookmark icon - how do I get my bookmarks back - they still show on Microsoft Explorer

    julianscars wrote:
    I don't get a page, all I get is the player popping
    Click the green jelly button at the top left of the player.

Maybe you are looking for

  • Private Key, Hash , sa password

    I didn't do the installation for this ecommerce site, I am just coming in later to customize the site and I was told that the initial installation was complete.  When I try and browse to the site of check sync manager I am getting 2 errors that I hav

  • Use of Transaction in Parallel flow

    Hi - I have created a SSIS package having 6 different DFT. All are loading data into different tables. So i want if one DFT fail then corresponding data of that DFT should roll back. I would like to use separate transaction for different data flow. S

  • DB 11g unzip fails

    Hi, I downloaded DB 11g (win32_11gR1_database.zip) from the Oracle download page and now the unzipping fails. I get "invalid format" error both with PowerArchiver and WinRAR. I downloaded three times, always the same issue. I saw some other posts wit

  • Adobe XI and Flashplayer XI

    After upgrading to Adobe Reader XI and Flashplayer XI I am unable to get any sound on my computer.  I submitted a question about an error message I was receiving and was instructed to uncheck the option for enable protected mode at startup.  Could th

  • Error in Java compilation in linux..

    Hello Friends., I am a Newbie.. I have sun Java in Fedora 8.. I am new to Java World too.. My java prog name is parsetrace.java., public class name is also same.. when i type [maran@fedora8 works]$ javac parsetrace.java No error is reported.. but whe