public class C { public static final String A = C.A; ... } what's point of this...
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...
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...
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...
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...
b*y
6 楼
不清楚
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.
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!!
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!!
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.
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.
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
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