javaoverloading

The compiler seems to be confusing two versions of an overloaded method. Why?


In my jsp file there is a line:

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

and eclipse complains:

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

It says that the method gets a String, but it expects a byte[]. But in the Base64 class there are two overloaded versions of decodeBase64; one with argument String, and one with argument byte[].

I fail to see why the compiler seems to think I am calling the byte[]version with an incorrect String argument, where it should have used the String version without any compiler error.


Solution

  • Base64 class in package org.apache.commons.codec.binary has 2 decode methods

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

    I think you must be having jar prior to commons codec 1.4 in your classpath

    Hope it helps.