Java about Finally, static

Source: Internet
Author: User

The two topics seen on the forum are as follows:

//why is the result 1 0 not 0 0 who can explain ?   Public classFinallydemo {Static intValue = 0; Static intInc () {returnvalue++; }       Static intDec () {returnvalue--; }       Static intGetResult () {Try {             returnInc (); } finally {             returnDec (); }     }            Public Static voidMain (string[] args) {System.out.println (GetResult ());     System.out.println (value); }  } 
 Public class Null {     publicstaticvoid  greet () {         System.out.println ("Hello World ");             Public Static void Main (string[] args) {         null;         X.greet ();         ((Null) x). greet ();         ((Null) NULL ). greet ();     }      }   //

The first one needless to say, the test is the implementation of the suffix increment/decrement operator (incredibly unknown), finally.

Simply put, the statements in the try must be executed first, and finally the statements must be executed behind the try. The only thing that makes a mouthful is that if there is a return, then the return statement of the try is staged, and the return! in finally is executed.

However, finally once return, try: Catch.. Finally, it's over . --try's return was ignored ... 囧

Second, the first time to see, according to the reply to Daniel said it is possible to test the invokestatic directive? --JVM instructions.

This expression is powerless, can only remember the conclusion, the static method of the call, independent of the object, the underlying should be based on the type of object directly find the calling method !!!

Java about Finally, static

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.