final keyword!

I, on the final keyword

  final keyword can be used to decorate classes, methods and variables (including members and local variables) and can not be inherited, can not be rewritten, not a secondary assignment.

Second, when modifying a variable final keyword, is a reference to a variable can not be changed, an object or a reference can not be changed?

  When the final modification of a key variable is referenced variables can not be changed, the content object reference variables referred to in or can be changed.

  E.g:

final String a = new String("内容");

  Execute the following statement reports compile errors:

a = new String("");

  If you change the content inside is compiled by:

a.append ( "new content");

Third, the difference between the final and static

With final modifications, mainly to "editing", thereby improving safety. The static focus on sharing and convenient. Create a static modification of the class function, it can be accessed directly through the class name, the class out of the new object, you can also share static function, or a static modification of common attributes.

  

Guess you like

Origin www.cnblogs.com/tudoukaoya/p/12230857.html