类/接口中的静态成员 [英] Static Members in a Class/Interface

查看:97
本文介绍了类/接口中的静态成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是更好的,我是否应该使用类名或使用Object访问静态成员?哪一个是首选的(低成本有效)?

今天我想到了一件事... Java支持多个接口实现但只有单个类扩展以避免模糊引用(数据/成员)。 Java设法避免方法歧义但不能模糊歧义;)然后问题是我的思维静态成员应该使用类名。但我不确定哪一个是低成本有效的?

展开 | 选择 | Wrap | 行号

解决方案

始终使用类名。任何查看代码的人都可以通过你如何调用它来告诉它是静态的。


@ r035198x


这就是你讲述编码约定的原因。
我的问题是..哪一个具有成本效益?


@dmjpro


我认为你的意思是把你的例子写成:

展开 | 选择 | Wrap | 行号< /跨度>

What would be the better, whether should i access the static members using class name or using Object? Which one is preferred(low-cost effective)?

Today a thing stroke into my mind... Java supports multiple Interface Implementation but only single class extension to avoid ambiguous reference(data/members). Java manages to avoid method ambiguity but can''t data ambiguity ;) Then the question stroke my mind static members should use using class name. But i am not sure which one is low-cost effective?

Expand|Select|Wrap|Line Numbers

解决方案

Use the class name always. Anyone looking at the code will be able to tell it''s a static just by how you called it.


@r035198x
This is what you telling about coding convention.
My question was ..which one was cost-effective?


@dmjpro
I think you meant to write your example as:

Expand|Select|Wrap|Line Numbers


这篇关于类/接口中的静态成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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