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

时间:2012-11-06 13:47:07

标签: java compiler-construction overloading

在我的jsp文件中有一行:

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

和eclipse抱怨:

  

Base64类型中的decodeBase64(byte [])方法不适用于参数(String)“

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

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

1 个答案:

答案 0 :(得分:9)

Base64中的

org.apache.commons.codec.binary类有2种解码方法

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

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

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

希望它有所帮助。