Redian新闻
>
我脑袋短路,大家来帮一下:
avatar
我脑袋短路,大家来帮一下:# Java - 爪哇娇娃
S*S
1
【 以下文字转载自 Immigration 讨论区 】
发信人: iq350 (iq350), 信区: Immigration
标 题: 今天发生的一件事,把我吓得半死[原创]
发信站: BBS 未名空间站 (Sun Jul 25 14:33:42 2010, 美东)
今天下午上了会儿网,忽然觉得非常的困,就跑回卧室去睡觉。
迷迷糊糊睡了不知道多久,忽然听到有个男人的声音在耳边低语,
说的是什么听不清也听不懂,似乎说的还是英语,我没管它继续睡
忽然又传来一阵非常恐怖的怪笑,把我一下惊醒了。
可是我还是能够听到男人低语的声音,说的应该是英语,声音非常低沉。
但是我一点也听不懂。
靠~难道我梦魇了?我抽了自己一个耳光,可是声音还在继续。
我僵在床上一动也不敢动了。这时候,天已经快黑下来了,外面似乎在
闪电,窗户外面一闪一闪的。我门窗也没有关好,风从阳台吹过来,刮
得房间里的吊灯来回的晃。那气氛说不出的诡异。
那个声音似乎停了。我刚想坐起来去看看到底是那传出来的声音,
忽然那个男人又开始怪笑,吓得我赶紧拿被子蒙住了头。
那个鬼就这样笑一会,说一会,断断续续,一遍遍的重复。
看来我真是撞鬼啦
avatar
h*0
2
下面例子中,b处加还是不加?
avatar
M*m
3
哈哈,我有一次也是这样,我觉得我电脑还是关了的。不过我是立马就知道声音的来源
,所以也没惊吓~~~~就是纳闷为啥电脑没自己sleep...

【在 S********S 的大作中提到】
: 【 以下文字转载自 Immigration 讨论区 】
: 发信人: iq350 (iq350), 信区: Immigration
: 标 题: 今天发生的一件事,把我吓得半死[原创]
: 发信站: BBS 未名空间站 (Sun Jul 25 14:33:42 2010, 美东)
: 今天下午上了会儿网,忽然觉得非常的困,就跑回卧室去睡觉。
: 迷迷糊糊睡了不知道多久,忽然听到有个男人的声音在耳边低语,
: 说的是什么听不清也听不懂,似乎说的还是英语,我没管它继续睡
: 忽然又传来一阵非常恐怖的怪笑,把我一下惊醒了。
: 可是我还是能够听到男人低语的声音,说的应该是英语,声音非常低沉。
: 但是我一点也听不懂。

avatar
g*g
4
b will give you a compilation error.

【在 h*****0 的大作中提到】
: 下面例子中,b处加还是不加?
avatar
v*l
5
这是哪位版主的马甲啊?

【在 S********S 的大作中提到】
: 【 以下文字转载自 Immigration 讨论区 】
: 发信人: iq350 (iq350), 信区: Immigration
: 标 题: 今天发生的一件事,把我吓得半死[原创]
: 发信站: BBS 未名空间站 (Sun Jul 25 14:33:42 2010, 美东)
: 今天下午上了会儿网,忽然觉得非常的困,就跑回卧室去睡觉。
: 迷迷糊糊睡了不知道多久,忽然听到有个男人的声音在耳边低语,
: 说的是什么听不清也听不懂,似乎说的还是英语,我没管它继续睡
: 忽然又传来一阵非常恐怖的怪笑,把我一下惊醒了。
: 可是我还是能够听到男人低语的声音,说的应该是英语,声音非常低沉。
: 但是我一点也听不懂。

avatar
h*0
6
what if I deleted b?

【在 g*****g 的大作中提到】
: b will give you a compilation error.
avatar
a*s
7
不一定是mitbbs的鬼版啊

【在 v***l 的大作中提到】
: 这是哪位版主的马甲啊?
avatar
m*t
8

I don't think you need b. UTF would
remain null if an exception is thrown.
The bigger question, though, is whether
you really want to skip the error if UTF
fails to load.

【在 h*****0 的大作中提到】
: what if I deleted b?
avatar
d*d
9
哈哈哈。我也有类似的经历,突然load好的视频响起来,吓我一跳。
avatar
h*0
10
if some jvm platform doesn't support utf-8, i would let the program die
without hesitation.

【在 m******t 的大作中提到】
:
: I don't think you need b. UTF would
: remain null if an exception is thrown.
: The bigger question, though, is whether
: you really want to skip the error if UTF
: fails to load.

avatar
h*0
11
and if I simply delete b, the variable UTF may not be initiated, compile
error.

【在 m******t 的大作中提到】
:
: I don't think you need b. UTF would
: remain null if an exception is thrown.
: The bigger question, though, is whether
: you really want to skip the error if UTF
: fails to load.

avatar
m*t
12

That's the opposite of what you are doing at c though, isn't it?

【在 h*****0 的大作中提到】
: if some jvm platform doesn't support utf-8, i would let the program die
: without hesitation.

avatar
h*0
13
what do you mean? c is the position why I use UTF, and if the platform doesn
't support it, the program will die at c.

【在 m******t 的大作中提到】
:
: That's the opposite of what you are doing at c though, isn't it?

avatar
m*t
14

doesn
Unless I'm missing something, you are relying on String.getBytes
to blow up upon a null charset name. That might work, but it's not
explicitly defined in the API, so I wouldn't trust it.
If you _want_ it to blow up, why not just let it blow up at
b then, instead of swallowing the exception there?

【在 h*****0 的大作中提到】
: what do you mean? c is the position why I use UTF, and if the platform doesn
: 't support it, the program will die at c.

avatar
Z*e
15
agree, in general, just avoid catching RuntimeExceptions

【在 m******t 的大作中提到】
:
: doesn
: Unless I'm missing something, you are relying on String.getBytes
: to blow up upon a null charset name. That might work, but it's not
: explicitly defined in the API, so I wouldn't trust it.
: If you _want_ it to blow up, why not just let it blow up at
: b then, instead of swallowing the exception there?

avatar
h*0
16
you make a good point. I can(maybe I should) add code at b to blow it up,
which would indicate that "UTF not supported, my program don't want to run
anymore". However, this doesn't solve the "variable not initiated" problem.

【在 m******t 的大作中提到】
:
: doesn
: Unless I'm missing something, you are relying on String.getBytes
: to blow up upon a null charset name. That might work, but it's not
: explicitly defined in the API, so I wouldn't trust it.
: If you _want_ it to blow up, why not just let it blow up at
: b then, instead of swallowing the exception there?

avatar
h*0
17
now I know what you mean. But my problem is actually about how to satisfy
the compiler.

【在 m******t 的大作中提到】
:
: doesn
: Unless I'm missing something, you are relying on String.getBytes
: to blow up upon a null charset name. That might work, but it's not
: explicitly defined in the API, so I wouldn't trust it.
: If you _want_ it to blow up, why not just let it blow up at
: b then, instead of swallowing the exception there?

avatar
m*t
18

Well you could solve that problem easily by not making
it final.

【在 h*****0 的大作中提到】
: you make a good point. I can(maybe I should) add code at b to blow it up,
: which would indicate that "UTF not supported, my program don't want to run
: anymore". However, this doesn't solve the "variable not initiated" problem.

avatar
h*0
19
by logic, I should make it final "in case it will be changed accidentally
somewhere else".:)

【在 m******t 的大作中提到】
:
: Well you could solve that problem easily by not making
: it final.

avatar
r*l
20
define a class, something like this:
public class FinalUTF8CharSet {
private CharSet charSet = null;
private FinalUTF8CharSet _instance = null;
private FinalUTF8CharSet() {
try {
charSet = CharSet.forName("UTF-8");
} catch (Exception e) {
// leave charSet as null
}
}
public static FinalUTF8CharSet getInstance() {
if (_instance == null) {
_instance = new FinalUTF8CharSet();
}
return _instance;

【在 h*****0 的大作中提到】
: by logic, I should make it final "in case it will be changed accidentally
: somewhere else".:)

avatar
h*0
21
多谢多谢。
我自己的办法是把原来的代码稍改一下
static {
Charset utf = null;
try {
utf = Charset.forName("UTF-8");
} catch (Exception e) {
//maybe add throw a runtime exception to let program die now
}
UTF = utf;
}
这样不管是编译器还是我都高兴了。

【在 r*****l 的大作中提到】
: define a class, something like this:
: public class FinalUTF8CharSet {
: private CharSet charSet = null;
: private FinalUTF8CharSet _instance = null;
: private FinalUTF8CharSet() {
: try {
: charSet = CharSet.forName("UTF-8");
: } catch (Exception e) {
: // leave charSet as null
: }

avatar
m*t
22

It's _private_ static, man. Nobody can accidentally change
it unless you let them. 8-)
But I'm glad both you and the compiler are happy now.

【在 h*****0 的大作中提到】
: by logic, I should make it final "in case it will be changed accidentally
: somewhere else".:)

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