java - 编译器似乎混淆了重载方法的两个版本。为什么?

标签 java compiler-construction overloading

在我的jsp文件中有一行:

byte[] imageData = Base64.decodeBase64(request.getParameter("imageBase64"));

并且 eclipse 提示:

The method decodeBase64(byte[]) in the type Base64 is not applicable for the arguments (String)"

它表示该方法获取一个 String,但它需要一个 byte[]。 但是在Base64 类中有两个重载版本的decodeBase64;一个带有参数 String, 一个带有参数 byte[]

我不明白为什么编译器似乎认为我在调用 byte[] 版本时使用了不正确的 String 参数,而它本应使用 没有任何编译错误的字符串版本。

最佳答案

org.apache.commons.codec.binary 中的

Base64 类有2 个解码方法

static byte[]   decodeBase64(byte[] base64Data) since beginning

static byte[]   decodeBase64(String base64String) since version 1.4.

我认为你的类路径中一定有 commons codec 1.4 之前的 jar

希望对您有所帮助。

关于java - 编译器似乎混淆了重载方法的两个版本。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13252393/

相关文章:

表达式中的 C++ 运算符重载

java - Java RXTX 与 Arduino 串口通信

java - 即使在命令行上告诉为 -D mapred.reduce.tasks=0 后,hadoop reduce 任务仍在运行

java - 针对 Facebook 的客户端身份验证

c++ - 在 C++ 函数中,指针与索引数组

c - C 中的内联实际上是如何减慢该程序的速度的?

compiler-construction - 在 "Real-World"应用程序中使用 ML

java - 转换参数如何影响 java 中的覆盖和重载方法?

java - 如何在 Jersey/Spring 中使用 @QueryParam 重载方法?

java - iText 版本 4.2.1 在 Maven 中央存储库中重定向