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

Jan*_*ter 8 java compiler-construction overloading

在我的jsp文件中有一行:

byte[] imageData = Base64.decodeBase64(request.getParameter("imageBase64"));
Run Code Online (Sandbox Code Playgroud)

和日食抱怨:

参数(String)中的方法decodeBase64(byte [])不适用于参数(String)"

它说该方法得到了一个String,但它期望一个byte[].但是在Base64课堂上有两个重载版本decodeBase64; 一个有参数String,一个有参数byte[].

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

Saj*_*ran 9

Base64org.apache.commons.codec.binary中的类有2种解码方法

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

static byte[]   decodeBase64(String base64String) since version 1.4.
Run Code Online (Sandbox Code Playgroud)

我认为你必须commons codec 1.4在你的类路径之前使用jar

希望能帮助到你.