• Post Reply Bookmark Topic Watch Topic
  • New Topic

performance and final method  RSS feed

 
Alex Kravets
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
 
Warren Dew
blacksmith
Ranch Hand
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.
 
Mike Polinsky
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...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!