Wondering how we can invoke static method g() from non-static method d()

class A {
final int x;
A() {
x = 1;
int f() {
return d(this,this);
int d(A a1, A a2) {
int i = a1.x;
g(a1);
int j = a2.x;
return j - i;
static void g(A a) {
// uses reflection to change a.x to 2
}

public class A {
     final int x;
     A() {
          x = 1;
     int f() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
          return d(this,this);
     int d(A a1, A a2) throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
          int i = a1.x;
          g(a1);
          int j = a2.x;
          return j - i;
     static void g(A a) throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
          // uses reflection to change a.x to 2
          //a.getClass().getField("x").setInt(a, 5);
          a.getClass().getDeclaredField("x").setInt(a, 5);
     public static void main(String[] args) throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException{
          A a = new A();
          System.out.println(a.f());
throws this exception:
Exception in thread "main" java.lang.IllegalAccessException: Can not set final int field A.x to (int)5
     at sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:55)
     at sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:79)
     at sun.reflect.UnsafeQualifiedIntegerFieldAccessorImpl.setInt(UnsafeQualifiedIntegerFieldAccessorImpl.java:114)
     at java.lang.reflect.Field.setInt(Field.java:802)
     at A.g(A.java:22)
     at A.d(A.java:13)
     at A.f(A.java:9)
     at A.main(A.java:27)

Similar Messages

  • I am sharing a apple id acount with my family but when i synced my phone to the computer it erased all of my imformation and put the other phone's imformation on it. I was wondering how I can prevent this from happening?

    I am sharing a apple id acount with my family but when I synced my iphone to the computer it erased all of my imformation and put the other phone's imformation on it. I was wondering how I can prevent this from happening?

    If the ringtones are on the old device just plug it in and do a transfer of purchases then they will be on the computer to sync to the new device.

  • I recently got a new computer and i was wondering how i can i transfer music from my ipod touch to my new computer

    i recently got a new computer and i was wondering how i can i transfer music from my ipod touch to my new computer

    See:
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive: Apple Support Communities
    or
    Recovering your iTunes library from your iPod or iOS device: Apple Support Communities

  • I just received a new ipad and presently have an ipad 1. I was wondering how i can transfer everything from my old one to my new one and keep the same accounts and passwords or is it even possible or do you have to repurchase all of your apps

    I have an ipad 1 and just receive the new one.  I was wondering how i can transfer the apps and things that i have on my old one to my new one and keep the same account names and passwords.  Or do I have to purchase averything over again.

    How to Transfer Everything from an Old iPad to New iPad
    http://osxdaily.com/2012/03/16/transfer-old-ipad-to-new-ipad/
     Cheers, Tom

  • How I can change Valuation Method from Moving Average to Standar

    Hi Experts:
    How I can change Valuation Method from Moving Average to Standar for an item that has bookings. We running Sap Business One 2007 A, PL 45...
    Thanks very in advance.
    Claudia

    Hi
    You can change the valuation method, but for that you need to have zero physical stock for that item.
    Make a Goods issue entry for that Item for all the warehouses, change the method and make goods receipt entry for that item for all the warehouse.
    Regards
    Kamlesh

  • I have a Macbook 2,1 and want to wipe it clean so as I can give it away.  I do not have any original start up disks and wondered how I can do this?

    I have a Macbook 2,1 and want to wipe it clean so as I can give it away.  I do not have any original start up disks and wondered how I can do this?

    If your Mac is running 10.6 like your signature says, then the 10.6.3 upgrade disks will work as they contain the full 10.6, you need to hold the option key down to select the disk to boot from.
    Once booted from the disk, Disk Utility is there to wipe the drive (use the Security Option > Zero) and then reinstall O S X 10.6.3 and then reboot, press the power button down to hard shutdown and the machine will stay like that to boot into the Welcome to Mac video for the next owner to setup.
    How to erase and install Snow Leopard 10.6
    How do I securely delete data from the machine?

  • Hello, just wondering how i can fix my itunes when i keep getting these msges, MSVCR80.dll was not found and error 7 (windows error 126). can anybody help. cheers.

    hello, just wondering how i can fix my itunes when i keep getting these msges, MSVCR80.dll was not found and error 7 (windows error 126). can anybody help. cheers.

    See Troubleshooting issues with iTunes for Windows updates.
    tt2

  • Hi! I just bought a new iPhone and I was wondering how i can make sure all my pictures and music will be transfered from my old iPhone to my new one?

    Hi! I just bought a new iPhone and I was wondering how i can make sure all my pictures and music will be transfered from my old iPhone to my new one?

    Pictures are held in the iPhone backup. If you backup the old device just prior to the activation of the new one, then restore from that backup, the photos will be there. Music is in iTunes on the computer and when you do the restore, it will download the music from iTunes to the device during the restore. Make sure any music purchased on the iPhone that has not been transfered to iTunes on the computer is done before beginning the restore.
    You can also view information in this support document http://support.apple.com/kb/HT2109

  • My ipod broke and i have a new computer and i was wondering how I can get my previous purchases on my new computer???

    My ipod broke and i have a new computer and i was wondering how I can get my previous purchases on my new computer???

    Download Past Purchases
    http://support.apple.com/kb/HT2519

  • How Can we get the data from Non-SAP to SAP in WebDynpro

    Hi,
    I hope u understand my query, How can we get the data from Non-SAP to SAP thru WebDynpro Programming.
    Help out with the steps for getting the data or procedure.
    Regards,
    Mutyapu

    You can expose the APIs in the Non-SAP backend as Web Services, and consume them in SAP by creating an Enterprise Proxy. Then these can be called just like normal class methods from Web Dynpro.
    Regards,
    Nithya

  • How do I invoke a Adobe Plugin from another Client application

    Hi,
    I have written a plug in for Adobe.
    I need to know how do i invoke this plug in from an external application
    For
    e.g a VB.NET Form has a button which on clicked would invoke this plug in
    Thanks for your suggestions in advance

    Leonard
    I would like to know how to do it
    I know that you can use IAC to call a plug-in
    I need to know the function call that i need to make in order make it happen
    MenuItemExecute doesnt seem to work for me.. or maybe i am doing something wrong there
    I can call menuitemexecute("SaveAs") but menuItemExecute("MyMenuItem")
    doesnt work
    Please advise

  • How I can create a XML file from java Aplication

    How I can create a XML file from java Aplication
    whith have a the following structure
    <users>
    <user>
    <login>anyName</login>     
    <password>xxxx</password>
    </user>
    </users>
    the password label must be encripted
    accept any suggestion

    Let us assume you have all the data from the jsp form in an java bean object..
    Now you want a xml file. This can be acheived in 2 ways
    1. Write it into a file using java.io classes. Say you have a class with name
    write("<name>"+obj.getName+</name>);
    bingo you have a flat file with the xml
    2. Use data binding to do the trick
    will recommend JiBx and Castor for the 2nd option
    Regards,
    Rajagopal

  • How we can automate the data loading from BI-BPC

    Dear  Guru's
    Thanks for watching this thread,my question is
                  How we can load the data from BI7.0 to BPC.My environment is SAP-BI 7.0 and BPC is 7.5 MS version and 2008SQL.
    How we can automate the data loading from  BI- BPC Ms version.Is manual flat file load is mandatory in ms version.
    Thanks in Advance,
    Srinivasan.

    Here are some options
    1) Use standars packages and schedule them :
        A) Openhub masterdata file into a flat file/ BPC App server  and Schedule the package - Import Master Data from a Data File and  other relevent packages.
    2 ) Using Custom Tasks in Custom Packages ( SSIS)
    Procedure
    From the Microsoft SQL Server Business Intelligence Developer Studio, open the Microsoft SSIS folder.
    Create a new package, or select an existing package to modify.
    Choose  Task  Register Custom Task .
    In the Task Location field, browse for the target .dll file.
    Note
    By default, the .dll files are stored in BPC/Websrvr/bin.
    End of the note.
    Enter a task description, select an appropriate icon, then click OK.
    Drag the icon to the designer window. Enter data as required.
    Save the package.

  • How we can import an IDOC structure from one SAP system to another w/o ALE

    Hi Gurus,
    How we can import an IDOC structure from one SAP system to another? we're not able to use ALE tech, these two sap systems are isolated.
    Any response will be awarded!
    Thanks a lot.
    Samson

    hi,
    1.One is by change pointer concept i.e by executing the RBDMIDOC.We can generate the idoc and automatically to the inbound System.
    2.By executable program also like bd10 and bd11.
    Regards,
    SHIVA(reward if helpful).

  • How we can import an IDOC structure from one SAP system to another

    Hi Gurus,
    How we can import an IDOC structure from one SAP system to another? If we're using ALE, how can we do that? Please can someone give me the process and necessary t codes.
    Any response will be awarded!
    Thanks a lot.
    Samson

    hi!
    Define the logical system names in both the systems.
    Logical system names :SAP001
    SAP002
    SAP001 FOR 001 CLIENT
    SAP002 FOR 002 CLIENT
    These two logical system definitions should be present in both the systems.
    Assign the logical systems to the client. (in both the systems)
    Assign SAP001 to 001 CLIENT
    Assign SAP002 to 002 CLIENT
    you can See these in transaction SALE.
    After this define the rfc DESTINATION IN sm59. (in both the systems)
    In 001 client create the RFC destination name SAP002
    In the tab log on security, give the user name and password and client of the 002 client and save it.
    Similarly do the reverse in the 002 Client.
    In 001 client create the port.(Transaction WE21)
    Specify the RFC destination name as SAP002.
    Now you can define the ports, (both the systems)
    Create the partner profile for partner(ie gve logical system name of partner) , so give as SAP002.
    partner profile in both the systems.
    Now create the distribution model in BD64 and goto edit>model view>distribute.
    The same model view will be visible n distributed to the partner system also..which in this case is sap002.
    U may trigger the idoc from we19 and chk its status in we05.
    Please let me know if you need further info on this.

Maybe you are looking for

  • I am facing lots of problems with security while using Mozilla. How can I send you a detailed report for this?

    I am getting redirected to unknown sites whenever I open any site while using mozilla. Initially I thought that there is a problem with my device, but then I realized that this happens only when using mozilla, not with other browsers like chrome, IE,

  • How do I change the subject of an inbox and outbox in order to organize them better

    I would like to change the Subject of received and sent mails in Thunderbird. I used to be able to do this with Eudora and it helped me to organize them better especially when the subject and content didn't match!

  • MacBook printer problem

    Good day. I am having a problem with my new MacBook and hope you can help. I have it connected to an HP 5550 deskjet printer via USB cable. I can print things off my desktop but when I try to print from an application (Photoshop, Illustrator) it unex

  • Verizon E-mail Page has a bogus ID

    When I log into my main Verizon E-Mail Page (I have a second) at the top right is an ID of {edited for privacy} This is not my main ID. I have a second/alternate ID. When I look at mail under that ID, my appropriate ID is displayed. Do I have a probl

  • Norton Antivirus HD scan

    When I scan the hard drive using Norton Antivirus, I get a list of files that it "Did not have permission to open the file." Is this normal? Shouldn't I be able to command Norton scan all my files? Below is a partial list of un-scanned files: .AppleS