How to access the inner class fields in refleciton?

I have:
class Outer {
    class Inner {
        int field;
    }
    Inner inner;
}
I use reflection to get the Outer.field field and recognize that it is a reference to the inner class. What should I do to get the inner.field (or something that looks remotely like this at Inner.field)?

We would like to

Well, precedent is too messy for me even follow my example. I've simplified it, and I think I found where my error was. I suspect that you were doing a similar error:

package scratch;

import java.lang.reflect.Field;

public class Scratch {

  public static void main(String[] args) throws Exception {
    new Scratch().go();
  }

  void go() {
    Outer1 o1;

    Field[] fields = Outer1.class.getDeclaredFields ();

    for (Field field : fields) {

      final String fn = field.getName ();
      final Class ft = field.getType ();
      final Class fc = field.getClass ();
      final Class fdc = field.getDeclaringClass ();

      System.out.println ();

      System.out.println ("Outer1 field : " + fn);

      System.out.println ();

      System.out.println ("field's class (field.getType()) : " + ft.getName());
      System.out.println ("field.getType().isMemberClass() (" + ft.getName() +" isMemberClass()) : " + ft.isMemberClass ());
      System.out.println ("field.getType(). getDeclaringClass() (" + ft.getName() + "'s declaring class) : " + fdc);

      System.out.println ();

      System.out.println ("field.getClass()) : " + fc.getName());
      System.out.println ("field.getClass().isMemberClass() (" + fc.getName() +" isMemberClass()) : " + fc.isMemberClass ());
      System.out.println ("field.getClass().getDeclaringClass() (" + fc.getName() + "'s declaring class) : " + fc.getDeclaringClass ());

      System.out.println ();

      System.out.println ("Note the difference between Field.getClass() (" + field.getClass () + ") and Field.getType() (" + field.getType() + ")");

      System.out.println ();
    }
  }
}

class Outer1 {
  class Inner1 {
  }

  Inner1 i1;
}

Outer1 field : i1

field's class (field.getType()) : scratch.Outer1$Inner1
field.getType().isMemberClass() (scratch.Outer1$Inner1 isMemberClass()) : true
field.getType(). getDeclaringClass() (scratch.Outer1$Inner1's declaring class) : class scratch.Outer1

field.getClass()) : java.lang.reflect.Field
field.getClass().isMemberClass() (java.lang.reflect.Field isMemberClass()) : false
field.getClass().getDeclaringClass() (java.lang.reflect.Field's declaring class) : null

Note the difference between Field.getClass() (class java.lang.reflect.Field) and Field.getType() (class scratch.Outer1$Inner1)

field.getClass () does NOT get the class of the field. It get the class of the field object that points to the field reference variable, which is always java.lang.reflect.Field. To get the class of the field, use field.getType ().

Do you see the difference?

Edited by: jverd February 5, 2011 17:18

Tags: Java

Similar Questions

  • How to access the static class variable calendar / singleton?

    How can I access a timeline of a static class variable / singleton?

    You can pass any object to display list to your class when instantiating it.  all objects in the display list has a placement property that allows access to the stage and them you can use the correct path/name to your variable.

  • How to access the inner workings of firefox (debugger) with mozrepl

    I want to use mozrepl to:
    -Open the js debugger
    -switching js file
    Toggle the breakpoint

    How to do?

    Best place to ask this question is in their support mailing list: https://groups.google.com/forum/#! for... /mozlab

  • final in the inner class

    I am trying to manually do a drawing similar to this program
    http://JavaFX.com/samples/draw/

    However, I'm running in final questions and internal classes.

    "size of a local variable is accessible from the inner class; must be declared final.

    He wants me to do either in SIZE or full size. However, once final, I can't change the variable.

    I have often used the variable in a loop for to assign a value (although perhaps it was a bad practice?) but I don't know the best way to handle this.

    Any suggestions?
    Thank you!


    int SIZE = 1; //somewhere else
    ...
            for( int size = 0 ; size < 5 ; size++){
                  Circle circle = new Circle(D/Padding);
                  
                  circle.setOnMousePressed(new EventHandler<MouseEvent>(){
                      public void handle(MouseEvent me){
                          SIZE = size;
                      }
                  }
             );
    Edit:
    I'm well aware that's not necessarily something specific to javafx, but more a general java programming failure.
    I also know that the mouseadapter is an anonymous class and can only access the final.

    I'm just looking for some suggestions on how to better fit this.

    Published by: namrog on July 5, 2011 10:51

    Published by: namrog on July 5, 2011 10:59
    int SIZE = 1; //somewhere else
    ...
            for( int size = 0 ; size < 5 ; size++){
                  final int size1 = size;
                  Circle circle = new Circle(D/Padding);
    
                  circle.setOnMousePressed(new EventHandler(){
                      public void handle(MouseEvent me){
                          SIZE = size1;
                      }
                  }
             );
    

    And Yes, it is a question of Java, not specific to JavaFX.
    http://Java.Sun.com/docs/books/JLS/third_edition/HTML/classes.html#247496

    DB

  • How to access the hard drive USB on E3000? Am I missing something?

    I have my router configuration fine to the internet, as well as the media server.  I can't understand how to access the hard drive of my laptop, however.  The manual says to put 192.168.1.1 in the field the address of windows Explorer, but it gives me just the 'Setup' page for the router.

    Am I missing something simple?  I use Windows XP.

    Click on start - go to start > Run/start search and type "\\192.168.1.1" (without the quotes) and press on enter and it should ask the user name and password, the user name and password, use "admin" all lower case, and then click Ok... Now you should be able to see your USB... You must make a right click on it and select "Map network drive" and check the Enable box and below click Finish... It will map the USB on your computer... Once done, you will be able to send and receive data from your computer to the USB...

  • How to get the controller class of the a fxml file open in a tab?

    Hello.
    First of all, sorry for my bad inglish, that is not my language.

    Introduction:
    I work in the skeleton of an enterprisse application in javafx. Generally (in the past), I used swing with InternalFrames MDI form. Search in the web site on how can he do this, I found that the concept of the MDI form is obsolete, is recommended to use a tabpanel structure. I started to develop the application with this concept, but I have a question.

    Scenario:
    I have a main window with:
    -Menu: To access the different options
    -Toolbar: To run the day-to-day operations (open, save, edit, delete and print)
    -TabPanel: To display the dashboard and fxml files opened from the menu.
    -Status bar: To display information.

    [http://www.blueboxmicrosystems.com/fxml.png |] See the image]

    The problem:
    I don't know how to access the methods of the controller of the fxml file on the active tab.

    Note: I have an interface with operations (open, save, edit, delete and print) and the tools of the interface controllers.

    The question:
    How can I me the controller class of the file fxml in the active tab in order to call methods?

    Kind regards

    Published by: user10311523 on 31-mar-2013 20:36

    Published by: m_ilio on 01-Apr-2013 05:40

    Instead of

     Parent root =  FXMLLoader.load(getClass().getResource(fxmlFile));
    

    do

    FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFile));
    Parent root = (Parent) loader.load();
    MyControllerType controller = loader.getController();
    // now you'll need to keep track of the controller somewhere, maybe a Map
    

    where of course you replace MyControllerType with classname of your controller.

  • How to display the serial No. field not to mention that the search results displayed

    How to display the serial No. field not to mention that the search results displayed

    Hello

    You missed to add the varstatus property in your table

    Try with this code:


    lines = ' #{bindings. " SahajDetailVO1.rangeSize}.
    emptyText = "#{bindings." SahajDetailVO1.viewable? "{'No data to display.': 'Access Denied.'}".
    fetchSize = "#{bindings." SahajDetailVO1.rangeSize}.
    rowBandingInterval = "0" id = "t1" styleClass = "AFStretchWidth."
    varStatus = 'vs' >



  • How to access the checkbox in mx:list

    I'm trying to access check boxes in my list

    < mx:List itemRenderer = "mx.controls.CheckBox" x = "0" y = "153" id = "listVocab" height = "297" width = "313" > < / mx:List > "

    but I can't find a way. That's what I do

    for (var i: int = 0; i < listVocab.numChildren; i ++)
    {

    If (I want to access the box here to see if she checked and then create the below but I don't know how to access the boxes?)

    {

    This gives me access to the text, but

    var password: String = listVocab.dataProvider [i] m:System.NET.SocketAddress.ToString ();

    }
    }

    Problem is with dataProvider your assignment to dataGrid is of type array of strings, which is why its saying selected there is no property to the string.

    Code given above by will work me for collection arrayCollection whose objects are of the following type instead of simple strings:

    public class CustomClass
    {

    public var data:String; Here id, you can store
    label public var:String; here Word you can store
            public var selected: Boolean;
    }

    You can make the change to

    public class CustomVocabulary
    {
    public var sentence: String;
    public var type: String;
    public var dbId:String;
    public var words: ArrayCollection collection; This will contain objects of type CustomClass.
    }

  • How to access the BPM 11 g load useful or process varibles in the workflow of ADF

    I'm trying to view/edit the data in a user interface that is linked to a database by using a foreign key, requestId. The foreign key comes from a BPM process where it is spent in the workflow, a human task. The foreign key comes process variables or values of payload. I know that I can simply load the payload in BPM with the data in the tables, but I'm looking for a better solution use the ADF business components to view and edit data directly in the user interface.

    The BPM process uses a web service to start the process. Web services takes a primary key as a parameter to reference a column in the database table. The data is pre-filled with content and a primary key reference. The first activity is an activity of the user. I want the workflow behind the user activity to accept this primary key and use to locate the line in the database, so related views of the database delimited ADF business components can work to present the data in the user interface.

    I tried two approaches to the problem. The first uses the setCurrentRowWithKeyValue operation. The other changes the SQL where clause, used by the ADFbc iterator only returns one row for the given requestId. Both of these approaches fail to work because I don't know how to access the load BPM or variable data entering the workflow. Here is the piece of code that I used to try to define the row using the value of setCurrentRowWithKey:

    public String setRequestId() {}

    FacesContext context = FacesContext.getCurrentInstance ();
    Object requestObj = context.getApplication () .evaluateExpressionGet)
    context, "#{bindings."(, Number.class) RequestId.inputValue "};
    If (requestObj is nothing)
    Returns a null value.
    RequestId number;
    requestId = (number) requestObj;

    ITR DCIteratorBinding = (DCIteratorBinding)

    getBindings () .get ("PatfRequestHdrView1");

    itr.setCurrentRowWithKeyValue (requestId.toString ());

    Returns a null value.

    I didn't get very far with the second approach, change SQL where clause, because I do not know Groovy. I think I need something like:

    adf.object.viewObj.RequestId. but it is not a viewObject associated with BPM data, so I don't know that this particular expression will not work.

    Any help you can give me is greatly appreciated.

    Kind regards
    Mark

    Try this code in your method:

    FacesContext context = FacesContext.getCurrentInstance ();
    String ctx = (String) context.getApplication () .evaluateExpressionGet (context, "#{pageFlowScope.bpmWorklistContext}", String.class);
    String tskId = (String) context.getApplication () .evaluateExpressionGet (context, "#{pageFlowScope.bpmWorklistTaskId}", String.class);
    IWorkflowServiceClient workflowSvcClient = WorkflowService.getWorkflowServiceClient ();
    ITaskQueryService wfQueryService = workflowSvcClient.getTaskQueryService ();
    IWorkflowContext wfContext = wfQueryService.getWorkflowContext (ctx);
    Task myTask = wfQueryService.getTaskDetailsById (wfContext, tskId);
    XMLElement xmlPayload = (XMLElement) myTask.getPayloadAsElement ();
    get the payload as a string simple, useful for debugging
    java.io.StringWriter writer = new java.io.StringWriter ();
    xmlPayload.print (writer);
    String payloadAsString = writer.toString ();
    extract payload values: use methods in Oracle XDK

    See also this post:

    The task of reading by program details

  • How to access the info in my iCloud account

    How to access the info in my iCloud account?

    You can access much of the iCloud.com on a computer or through specific applications on your mobile device such as contacts, calendars, iCloud Drive, Photos. What exactly you were looking for and what type of device.

  • How to access the bios?

    I am trying to install a new OS, how to access the bios on my HP Pavilian dv8?

    Hello:

    You should be able to access the BIOS by pressing the F10 key as soon as you see the HP welcome screen.

    Paul

  • How to access the BIOS on a Pavilion Elite e9237c with mouse and keyboard wireless?

    I have a desktop computer Pavilion Elite e9237 with a wireless keyboard and mouse. I tried to access the BIOS by pressing F10 at startup with no luck, and I can't access any of the other menus for the start-up eiither. I don't have a PS/2 port on my computer, so I can't get a wired keyboard and mouse. Does anyone know how to access the BIOS with this configuration?

    I bought a USB keyboard and he answered in the same way... No bios access. I then studied why it did not work and discovered that it was the way in which he has been connected to the computer. I had initially plugged into a USB hub when he was not working and I moved it directly into a USB port and it works! I plugged my keyboard wireless directly into the USB port and it works too! Thanks for your help... I wouldn't have thought of it if it wasn't for to recommend you the USB keyboard.

  • How to access the firefox on laptop Office keeping all the features?

    How to access the firefox on laptop Office keeping all tabs and bookmarks?

    Hello

    You may be able to do this in Firefox Sync configuration on both devices. Please see for detailed instructions.

  • Qosmio G30-126 - how to access the bios!

    I have a laptop Qosmio G30-126 and I don't know the key to enter the bios to change real estate for the HARD drive or something... then how to access the bios? What is the key for the bios?

    Hello

    Try pressing the F2 key by turning on the device.
    The Toshiba notebooks supported the ESC and then F1 button
    If these two options are possible

  • Re: How to access the BIOS on Satellite Pro A120

    Can someone tell me how to access the BIOS on my SAT Pro A120?

    Hello

    You must press ESC and then F1 key immediately after the laptop has been powered!

    The laptop seems to be to use the Toshiba BIOS and ESC key should be the right one!

    Good bye

Maybe you are looking for

  • How can I change the shema for the file name used during the recording of emails?

    By default, it is something like "subject - < address > - YYYY-MM-DD hhmm.eml".I would like to have something like "YYYY-MM-DD hhmm - < address > - subject.eml", so it can be sorted by 'right' of the file Explorer.Can't find anything in all: config o

  • Server.app and port 4444

    I was checking my open ports on my Mac server recently and noticed that the port 4444 was open. (To my knowledge) I have not all installed services using this port, so I was a little confused. All that is using this port runs under launchd so I can't

  • Cannot choose to update its time of 7.7.3 7.7.7

    Hello! I sincerely hope that's no stupid question... I simply can't update my Capsulte time: I opened the airport serviceprogram, see my time its and voila! There is a red "1!" right on behalf of my TC blinking in orange. When I click on the Red "1",

  • Satellite M60: I can boot from firewire device?

    Satellite M60 - a BIOS toshiba 1, 60 - it can boot from firewire device - it has usb as a boot option, but no FireWire? and this BIOS is PHOENIX or really toshiba? There is no manual available that can tell me this. can somone helpPraveen

  • Satellite A200-1FL: where can I get all the drivers XP and SATA HDD

    Where I can get the controller to sata drives so that it (he, she) can load Xp in Satellite A200-1FL. And another serious issue that when available have all the drivers for this model is only it (he, she) has 2 just now in the Journal official page t