valueOf() 的问题,在 Java 中将字符转换为字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1741037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
problem with valueOf(), converting a char to Character in Java
提问by Fred
I'm trying to convert a char to Character before it gets pushed on a stack but get a "cannot find symbol error", I don't see what the problem might be. This is how I pass the char to the stack:
我试图在将字符压入堆栈之前将其转换为字符,但出现“找不到符号错误”,我看不出问题是什么。这就是我将字符传递给堆栈的方式:
stack.push(valueOf(in));
Where 'in' is a char.
其中 'in' 是一个字符。
采纳答案by Carl Smotricz
valueOf
is a class method of Character
, among others. You can't just call it without a class to hang it off.
valueOf
是 的一个类方法Character
,等等。你不能在没有课程的情况下调用它来挂断它。
What you're really looking for is
你真正要找的是
Character.valueOf(in)
or new Character(in)
.
Character.valueOf(in)
或new Character(in)
。
回答by rsp
You are looking for:
您正在寻找:
stack.push(Character.valueOf(in));
回答by Andreas Dolk
I hope, valueOf(char c)
is defined in the same class where you have that call ... ;)
我希望,valueOf(char c)
是在你有那个电话的同一个班级中定义的......;)