While I understand that sealed can be used for security reasons, a few people use the sealed keyword on leaf nodes as an optimization technique.
How does this help optimization? Why isn’t the compiler smart enough to figure this out itself?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In a sealed class, calls to virtual methods can bypass the usual virtual method lookup and go directly to the most-derived virtual method implementation instead. In principle, the compiler/JIT could also inline these calls.
The compiler can’t figure it out for non-sealed classes, because any code could come along after compilation and inherit from your class: the compiler must assume the worst case.