Adding default method to java.lang.Cloneable

Rémi Forax forax at univ-mlv.fr
Fri Mar 2 06:57:01 PST 2012


I've tried to add a default method to java.lang.Cloneable
in order to be able to call it on an array
(all arrays inherits from Object and implements Cloneable and Serializable).

But the VM doesn't like that :)
I think it's a bug.

Here is the code
package java.lang;

public interface Cloneable {
   public String foo() default {
     return "foo";
   }
}

---

public class Main {
   public static void main(String[] args) {
     int[] array = new int[] {2, 4 };
     System.out.println(array.foo());
   }
}

---

Rémi





More information about the lambda-dev mailing list