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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 22:07:09  来源:igfitidea点击:

problem with valueOf(), converting a char to Character in Java

javacharacter

提问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

valueOfis 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)是在你有那个电话的同一个班级中定义的......;)