由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - anyone saw this on code?
相关主题
刚刚开始学习java,麻烦帮我看一下我哪里错了行吗?谢谢问个面试题, 谢谢
thread safe Singleton 的几种方法?问一个java的面试题 (转载)
what is your opinion in this case?a question regarding spring collection initialization
interestingSuggestion Re: 发现 synchronized 的一个问题
basic java question自己管理session要每次手动释放么
NullPointerException 问题Where does Java Store Static Variable?
问一个java基础的初始化的问题,一直搞不明白 (转载)求教:Facade Pattern vs Static Variable
help on this scope questionJAVA 求解
相关话题的讨论汇总
话题: final话题: static话题: code话题: saw话题: class
进入Java版参与讨论
1 (共1页)
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 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: public class C
: {
: public static final String A = C.A;
: ...
: }
: what's point of this...

b******y
发帖数: 9224
6
不清楚
I*******o
发帖数: 53
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
发帖数: 2999
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
发帖数: 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 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: 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 的大作中提到】
: it is defined final.
: so this code is doing nothing and it is confusing people, which should be
: avoided.
:
: to

1 (共1页)
进入Java版参与讨论
相关主题
JAVA 求解basic java question
问一个特别土的问题NullPointerException 问题
新手问题 -- dynamic variable and dynamic functions.问一个java基础的初始化的问题,一直搞不明白 (转载)
a question about jnihelp on this scope question
刚刚开始学习java,麻烦帮我看一下我哪里错了行吗?谢谢问个面试题, 谢谢
thread safe Singleton 的几种方法?问一个java的面试题 (转载)
what is your opinion in this case?a question regarding spring collection initialization
interestingSuggestion Re: 发现 synchronized 的一个问题
相关话题的讨论汇总
话题: final话题: static话题: code话题: saw话题: class