avatar
Re: Java Tip: Constant# Java - 爪哇娇娃
G*s
1
发信人: Godwithus (神与我们同在), 信区: sysop
标 题: Re: D大: 請說明哪些是故意刪的 (转载)
发信站: BBS 未名空间站 (Tue Jun 28 16:03:45 2011, 美东)
泄露隐私不好吧?
目前我有2个ID在本站。其实老早以前就注册了,不过基本不来这里
现在用这个中间被饿死了,后注册的

两个ID都是主要用的ID,没有把那个作为MJ
真想不通为什么总有很多人问个不停
avatar
xt
2

Yes, this works, but it is not a good idea.
First, it does not make sense to implement a constant interface.
Interface means ADT, and what does a constant interface mean?
Second, implementing such an interface gives rise to naming
clashes. For example:
public interface A {
public static final int a = 1;
}
public interface B {
public static final int a = 2;
}
If you implement both interfaces, there you have to think how
the a is evaluated. If you want to be specific, A.a, B.a is better
w
avatar
c*g
3
你知道什么叫主ID不?
avatar
xt
4
Just some personal follow up ideas:
It does not kill you if you type a little more to make the program
more readable and better in style. We have been using vi editor
to write everything (excluding GUI design sometimes, but some
people actually write PowerJ scripts with vi instead of using
the PowerJ GUI to design frames as well. Even my co-op student
knows how to do it). Implementing interfaces with nothing but
constants is bad idea in terms of software engineering.
More typing may cost you tim

【在 xt 的大作中提到】
:
: Yes, this works, but it is not a good idea.
: First, it does not make sense to implement a constant interface.
: Interface means ADT, and what does a constant interface mean?
: Second, implementing such an interface gives rise to naming
: clashes. For example:
: public interface A {
: public static final int a = 1;
: }
: public interface B {

avatar
h*o
5
这个是另外一个ID
目前没有密码被盗。
都是本人发言。
好了吧。

【在 G*******s 的大作中提到】
: 发信人: Godwithus (神与我们同在), 信区: sysop
: 标 题: Re: D大: 請說明哪些是故意刪的 (转载)
: 发信站: BBS 未名空间站 (Tue Jun 28 16:03:45 2011, 美东)
: 泄露隐私不好吧?
: 目前我有2个ID在本站。其实老早以前就注册了,不过基本不来这里
: 现在用这个中间被饿死了,后注册的
:
: 两个ID都是主要用的ID,没有把那个作为MJ
: 真想不通为什么总有很多人问个不停

avatar
m*t
6
I am with xt on this one. The basic point is, think about it
in OO way, that is, constants are also part of your data, rather
than just some macros in C. And you need to organize and encapsulate
your data into classes.
If you have either a good memory(which I don't have), or an IDE
supporting abbreviation/auto completion(which I do), typing long
variable names is never a big problem. 8-)
avatar
G*e
7
另一个主ID在此版发过言吗?
avatar
m*t
8
Forte Community Edition is a commercial wrap-up for Netbeans.
Netbeans is open-source, but sponsored by Sun(that is, Sun is
cutting the pay checks)
Sun is planning on releasing the Prof. and Ent. Edition. But
won't be free.
I'd suggest you to go to www.netbeans.org. and download
Netbeans 3.0. It's a full-fledged Java IDE.
avatar
c*g
9
刷屏王活麦克尼都不知道,不信圣经的人真是。。。

【在 G******e 的大作中提到】
: 另一个主ID在此版发过言吗?
avatar
m*e
10
I do not agree with some of your points.
1. Sometimes it is good practice to use interface to define constants.
A good example in JDK is the SwingConstants interface. It defined
many constants which are used elsewhere in javax.swing package.
2. About the naming confusion, I think the programer should be responsible
for this. If a programmer always names his variables as things like
'a' or 'b', surely he will have trouble from time to time.
3. If we name the constants properly, there
avatar
G*s
11
发过

【在 G******e 的大作中提到】
: 另一个主ID在此版发过言吗?
avatar
m*t
12

First of all, while we all agree the Java core classes can be used
as classic examples for certain patterns or feature usage, not every
single bit of them is so "holy" and indisputable.
In the case of SwingConstants (and also some IO classes mentioned
in some previous post), the purpose of this separate interface is
to define constants that are used in so many swing classes that it is
inappropriate to define them repeatedly in all those classes. However,
the designer didn't put *all* constants

【在 m*****e 的大作中提到】
: I do not agree with some of your points.
: 1. Sometimes it is good practice to use interface to define constants.
: A good example in JDK is the SwingConstants interface. It defined
: many constants which are used elsewhere in javax.swing package.
: 2. About the naming confusion, I think the programer should be responsible
: for this. If a programmer always names his variables as things like
: 'a' or 'b', surely he will have trouble from time to time.
: 3. If we name the constants properly, there

avatar
G*e
13
噢,原来是这个呀。
遮遮掩掩地这么久,要不是那个切蛋蛋报料出来.....

【在 h*o 的大作中提到】
: 这个是另外一个ID
: 目前没有密码被盗。
: 都是本人发言。
: 好了吧。

avatar
xt
14

Yes, there can be data members in interfaces. If the
interface is not
for constant definations only, there should be some methods
or semantic
features. In this case, the data members should be related
to the features
otherwise it does not make sense to put them there.
Considering following example, do you think it makes sense:
public interface MyConstants1 {
public static final int a = 1;
}
public interface MyConstants2 {
public static final int a = 2;
public static final int b = 3;
avatar
G*e
15
好了,八卦完了,回家喽
avatar
G*e
16
提醒一下:楼主要做好备份
avatar
G*s
17
谢谢
我发到自己邮箱了

【在 G******e 的大作中提到】
: 提醒一下:楼主要做好备份
avatar
i*t
18
隐私?

【在 G*******s 的大作中提到】
: 发信人: Godwithus (神与我们同在), 信区: sysop
: 标 题: Re: D大: 請說明哪些是故意刪的 (转载)
: 发信站: BBS 未名空间站 (Tue Jun 28 16:03:45 2011, 美东)
: 泄露隐私不好吧?
: 目前我有2个ID在本站。其实老早以前就注册了,不过基本不来这里
: 现在用这个中间被饿死了,后注册的
:
: 两个ID都是主要用的ID,没有把那个作为MJ
: 真想不通为什么总有很多人问个不停

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。