由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - BufferedWriter里的write()
相关主题
这段程序的输出是什么? 为什么very weird problem
SpringMVC可否直接处理doGet?what is your opinion in this case?
问一个blocking IO的程序新手请教一个问题
help! string format???java,多层map应该怎么写?求个葫芦
请问有没有generic的array一个Java程序员的话(3)
java 的函数 xxx(a, b,c)能够向a 写入数据吗?能否让函数返回一个用于赋值的引用
问个primitive type的问题一个简单的关于java Map的问题
关于char和int的问题Java 问题
相关话题的讨论汇总
话题: string话题: write话题: int话题: special
进入Java版参与讨论
1 (共1页)
c*********n
发帖数: 128
1
write
public void write(int c)
throws IOException
Write a single character.
Overrides:
write in class Writer
Throws:
IOException - If an I/O error occurs
这里说的是write a single character,但怎么输入参数却是int呢?
比如我要写一个字符 'c'到这个 BufferedWriter bw里面去,怎么写呢?
bw.write('c')就可以了么?
g*****g
发帖数: 34805
2
char can be casted to int, I think it should work.

【在 c*********n 的大作中提到】
: write
: public void write(int c)
: throws IOException
: Write a single character.
: Overrides:
: write in class Writer
: Throws:
: IOException - If an I/O error occurs
: 这里说的是write a single character,但怎么输入参数却是int呢?
: 比如我要写一个字符 'c'到这个 BufferedWriter bw里面去,怎么写呢?

c*********n
发帖数: 128
3
我觉得逻辑应该是反过来的, + 运算符只对String类型重载
好比method的重载
已经有了
methodName(int parameter)
现在重新写一个
methodName(String strParameter)

Well that's what it's special about - String is the only class that supports
overloading +.
g*****g
发帖数: 34805
4
char->short->int->double, you don't need to cast in
that direction.

【在 c*********n 的大作中提到】
: 我觉得逻辑应该是反过来的, + 运算符只对String类型重载
: 好比method的重载
: 已经有了
: methodName(int parameter)
: 现在重新写一个
: methodName(String strParameter)
:
: Well that's what it's special about - String is the only class that supports
: overloading +.

c*********n
发帖数: 128
5
我已经试过了, 这个的确是可以的
但java不是号称是严格检查数据类型的语言么?
难道这里也可以像c语言一样自动转换类型而不需要在c前面加上(int)?

char can be casted to int, I think it should work.

【在 g*****g 的大作中提到】
: char can be casted to int, I think it should work.
c*********n
发帖数: 128
6
我觉得逻辑应该是反过来的, + 运算符只对String类型重载
好比method的重载
已经有了
methodName(int parameter)
现在重新写一个
methodName(String strParameter)

Well that's what it's special about - String is the only class that supports
overloading +.
p***p
发帖数: 559
7
Primitive Type is not object
but string is special object, is it right_

【在 c*********n 的大作中提到】
: 我觉得逻辑应该是反过来的, + 运算符只对String类型重载
: 好比method的重载
: 已经有了
: methodName(int parameter)
: 现在重新写一个
: methodName(String strParameter)
:
: Well that's what it's special about - String is the only class that supports
: overloading +.

r****n
发帖数: 1088
8
String is not primitive type. String extends from Object. String is immutable,
which makes String "special".

【在 p***p 的大作中提到】
: Primitive Type is not object
: but string is special object, is it right_

m******t
发帖数: 2416
9

Well that's what it's special about - String is the only class that supports
overloading +.

【在 c*********n 的大作中提到】
: 我觉得逻辑应该是反过来的, + 运算符只对String类型重载
: 好比method的重载
: 已经有了
: methodName(int parameter)
: 现在重新写一个
: methodName(String strParameter)
:
: Well that's what it's special about - String is the only class that supports
: overloading +.

m******t
发帖数: 2416
10

Good point, too.

【在 g*****g 的大作中提到】
: char->short->int->double, you don't need to cast in
: that direction.

相关主题
java 的函数 xxx(a, b,c)能够向a 写入数据吗?very weird problem
问个primitive type的问题what is your opinion in this case?
关于char和int的问题新手请教一个问题
进入Java版参与讨论
c*****t
发帖数: 1879
11
The reason is actually because all string literals are stored in a
hash table in class file. So duplicate strings are eliminated in the
compiled class file.
There are some horrible programmers at Sun that does things like
variable == "Center"
in the code. Maybe they knew it better, but still it is a bad
approach.

【在 g*****g 的大作中提到】
: char->short->int->double, you don't need to cast in
: that direction.

c*********n
发帖数: 128
12
char->short?
or
byte->short?

char->short->int->double, you don't need to cast in
that direction.

【在 g*****g 的大作中提到】
: char->short->int->double, you don't need to cast in
: that direction.

m******t
发帖数: 2416
13

Good question. I have always wondered why, too.

【在 c*********n 的大作中提到】
: char->short?
: or
: byte->short?
:
: char->short->int->double, you don't need to cast in
: that direction.

m******t
发帖数: 2416
14

Right, that's what's special about String. I don't see any material difference
in what we are saying, man. 8-)

【在 c*********n 的大作中提到】
: 我觉得逻辑应该是反过来的, + 运算符只对String类型重载
: 好比method的重载
: 已经有了
: methodName(int parameter)
: 现在重新写一个
: methodName(String strParameter)
:
: Well that's what it's special about - String is the only class that supports
: overloading +.

c*********n
发帖数: 128
15
thanks!

http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter02/castsMixing.html

【在 g*****g 的大作中提到】
: char->short->int->double, you don't need to cast in
: that direction.

m******t
发帖数: 2416
16

immutable,
Hmm, I'm not sure about that - many classes are immutable. I think String is
special because it's the only non-primitive type that supports operator +, and
the compiler does some special optimization supporting that.

【在 r****n 的大作中提到】
: String is not primitive type. String extends from Object. String is immutable,
: which makes String "special".

1 (共1页)
进入Java版参与讨论
相关主题
Java 问题请问有没有generic的array
overloading methodsjava 的函数 xxx(a, b,c)能够向a 写入数据吗?
Urgent!问个primitive type的问题
ERROR!java.io.RandomAccessFile.readInt关于char和int的问题
这段程序的输出是什么? 为什么very weird problem
SpringMVC可否直接处理doGet?what is your opinion in this case?
问一个blocking IO的程序新手请教一个问题
help! string format???java,多层map应该怎么写?求个葫芦
相关话题的讨论汇总
话题: string话题: write话题: int话题: special