Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

performance and final method

 
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By definition when final method is declared in a class, any method that inherits that class cannot override final method or hide it. Two questions, overriding I understand, but what does it mean not be able to hide that method. And, how does making a method final affects performance?

thanks,
Alex
 
blacksmith
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'Hiding' a function means writing a function in a subclass with the same name, which would then 'hide' the original function if called on the subclass, even though it wouldn't override the original function if an object of the subclass were called as the superclass. Some languages allow this.

A final function can be more efficient than a virtual method because the compiler can resolve the function at compile time, while virtual function resolution typically has to be deferred until run time. For example, a small final function can often be inlined by the compiler, saving the function call overhead, while a virtual function typically cannot, since the compiler doesn't know whether the function is overridden.

With today's dynamically recompiling Java virtual machines, though, I doubt that the efficiency advantage is enough to worry about in most cases.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks!
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah, thanks...
 
Crusading Chameleon likes the size of this ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic