I*******o 发帖数: 53 | 1 public class C
{
public static final String A = C.A;
...
}
what's point of this... |
g*****g 发帖数: 34805 | 2 I don't know, I would use
import static C;
if it's for shorten name.
【在 I*******o 的大作中提到】![](/moin_static193/solenoid/img/up.png) : public class C : { : public static final String A = C.A; : ... : } : what's point of this...
|
A**o 发帖数: 1550 | 3 does it compile and does it work?
very interesting static hell.
【在 I*******o 的大作中提到】![](/moin_static193/solenoid/img/up.png) : public class C : { : public static final String A = C.A; : ... : } : what's point of this...
|
s***e 发帖数: 122 | 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 的大作中提到】![](/moin_static193/solenoid/img/up.png) : public class C : { : public static final String A = C.A; : ... : } : what's point of this...
|
Z****e 发帖数: 2999 | 5 don't see the point, it's functionally equivalent to
public static final String A = null;
【在 I*******o 的大作中提到】![](/moin_static193/solenoid/img/up.png) : public class C : { : public static final String A = C.A; : ... : } : what's point of this...
|
b******y 发帖数: 9224 | |
I*******o 发帖数: 53 | 7 i saw this crap from someone's code when i was fixing a bug
it compiles!!
【在 A**o 的大作中提到】![](/moin_static193/solenoid/img/up.png) : does it compile and does it work? : very interesting static hell.
|
Z****e 发帖数: 2999 | 8 it's a valid statement, but meaningless
【在 I*******o 的大作中提到】![](/moin_static193/solenoid/img/up.png) : i saw this crap from someone's code when i was fixing a bug : it compiles!!
|
A**o 发帖数: 1550 | 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 的大作中提到】![](/moin_static193/solenoid/img/up.png) : i saw this crap from someone's code when i was fixing a bug : it compiles!!
|
I*******o 发帖数: 53 | 10 holly.... i was first surprised it complied!
maybe it's intended to be used as a placeholder.
【在 A**o 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 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.
|
Z****e 发帖数: 2999 | 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 的大作中提到】![](/moin_static193/solenoid/img/up.png) : holly.... i was first surprised it complied! : maybe it's intended to be used as a placeholder.
|
S*********t 发帖数: 78 | 12 it is defined final.
so this code is doing nothing and it is confusing people, which should be
avoided.
to
【在 Z****e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 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
|
Z****e 发帖数: 2999 | 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 的大作中提到】![](/moin_static193/solenoid/img/up.png) : it is defined final. : so this code is doing nothing and it is confusing people, which should be : avoided. : : to
|