私人建设者和最终 [英] private constructor and final

查看:82
本文介绍了私人建设者和最终的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么将一个只有私有构造函数的类标记为final是一个好习惯?我的猜测是,让其他程序员知道它不能被分类。

Why is it a good practice to mark a class with only private constructors as final? My guess is, it is to let other programmers know that it cannot be sub-classed.

推荐答案

让一个班级决赛有一些(小)性能增益,因为JIT编译器可以内联该类的功能。我不知道这是否符合'良好做法',但我看到了优势。

Making a class final has some (small) performance gain, because the JIT compiler can inline functionality from that class. I don't know if that qualifies as 'good practice', but I see the advantages.

这篇关于私人建设者和最终的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆