Da Ultimate

Java Quiz

Ego boost

  • Nicolas PERU
  • @benzonico
  • Work @Sonarsource
  • On Java plugin

[ ]

[])[][]{
int[] foo(int[] a[])[][]{
    return null;
}
int[][][] foo(int[][] a){
    return null;
}

...

void foo(String... strings){}

void foo(String s, String... strings){}
void foo(String... strings){}

void foo(String s, String... strings){}

void bar() {
  foo("");
}

Ambiguous method call

<T>

interface F1 {}
interface F2 {}

class A<T extends F1 & F2> {
  void method(F1 f1) { }
  void method(T t){  }
}
interface F1 {}
interface F2 {}

class A<T extends F2 & F1> {
  void method(F1 f1) { }
  void method(T t){  }
}

JLS: The erasure of a type variable is the erasure of its leftmost bound.

interface F1 {}
interface F2 {}
class B implements F1, F2{}

class A<T extends F2 & F1> {
  void method(F1 f1) { }
  void method(T t){  }
  void test{
   method(new B());//???
  }
}
interface F1 {}
interface F2 {}
class B implements F1, F2{}

class A<T extends F2 & F1> {
  void method(F1 f1) { }
  void method(T t){  }
}

class C implements F2, F1 {
  void test(){
    new A<B>().method(new B()); //???
  }
}

Da Ultimate Java Quiz

By Nicolas PERU

Da Ultimate Java Quiz

  • 989