avatar
anyone saw this on code?# Java - 爪哇娇娃
I*o
1
public class C
{
public static final String A = C.A;
...
}
what's point of this...
avatar
g*g
2
I don't know, I would use
import static C;
if it's for shorten name.

【在 I*******o 的大作中提到】
: public class C
: {
: public static final String A = C.A;
: ...
: }
: what's point of this...

avatar
A*o
3
does it compile and does it work?
very interesting static hell.

【在 I*******o 的大作中提到】
: public class C
: {
: public static final String A = C.A;
: ...
: }
: what's point of this...

avatar
s*e
4
It's the same as A = A; or probably A = null; (how could we be sure???)
as a static final field, it has to be initialized when the class is loaded.
but i don't like such tricky thing.

【在 I*******o 的大作中提到】
: public class C
: {
: public static final String A = C.A;
: ...
: }
: what's point of this...

avatar
Z*e
5
don't see the point, it's functionally equivalent to
public static final String A = null;

【在 I*******o 的大作中提到】
: public class C
: {
: public static final String A = C.A;
: ...
: }
: what's point of this...

avatar
b*y
6
不清楚
avatar
I*o
7
i saw this crap from someone's code when i was fixing a bug
it compiles!!

【在 A**o 的大作中提到】
: does it compile and does it work?
: very interesting static hell.

avatar
Z*e
8
it's a valid statement, but meaningless

【在 I*******o 的大作中提到】
: i saw this crap from someone's code when i was fixing a bug
: it compiles!!

avatar
A*o
9
haha, happy reading. :)
in that case, find the most senior or the most knowledgable employee
to find out if there is any story behind it.

【在 I*******o 的大作中提到】
: i saw this crap from someone's code when i was fixing a bug
: it compiles!!

avatar
I*o
10
holly.... i was first surprised it complied!
maybe it's intended to be used as a placeholder.

【在 A**o 的大作中提到】
: haha, happy reading. :)
: in that case, find the most senior or the most knowledgable employee
: to find out if there is any story behind it.

avatar
Z*e
11
here's my understanding:
variables on stack must be intialized; that's why if you define a variable
in a routine, and try to use it without initializing it, you'll get a
compiler error
variables on heap, like class variables, are preinitialized with null/0/
false when the memory space for the class is allocated; that's why you can
make reference to it even without initializing it. so when compiler sees
that statement, it will just try to assign the preinitialized value of A to
A again, which is

【在 I*******o 的大作中提到】
: holly.... i was first surprised it complied!
: maybe it's intended to be used as a placeholder.

avatar
S*t
12
it is defined final.
so this code is doing nothing and it is confusing people, which should be
avoided.

to

【在 Z****e 的大作中提到】
: here's my understanding:
: variables on stack must be intialized; that's why if you define a variable
: in a routine, and try to use it without initializing it, you'll get a
: compiler error
: variables on heap, like class variables, are preinitialized with null/0/
: false when the memory space for the class is allocated; that's why you can
: make reference to it even without initializing it. so when compiler sees
: that statement, it will just try to assign the preinitialized value of A to
: A again, which is

avatar
Z*e
13
with or without final, the line of code is doing nothing; adding a final
further rendered the vairable uselss because it can no longer be assigned to
any other value

【在 S*********t 的大作中提到】
: it is defined final.
: so this code is doing nothing and it is confusing people, which should be
: avoided.
:
: to

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