Bug 1518 : Static method declaration with nested generic parameters fails compile
Last modified: 2010-03-17 12:44




Status:
RESOLVED
Resolution:
FIXED -
Priority:
P2
Severity:
normal

 

Reporter:
heuermh
Assigned To:
MrFeinberg

Attachment Type Created Size Actions

Description:   Opened: 2010-03-16 12:53
version:

processing-0180

error:

The method binarySearch() in the type comparator is not applicable for the
arguments (List<String>, String)

source:

import java.util.ArrayList;
import java.util.List;

void setup()
{
List<String> list = new ArrayList<String>();
list.add("foo");
list.add("bar");
list.add("baz");

binarySearch(list, "bar");
}

static <T> int binarySearch(List<? extends Comparable<? super T>> list, T
key) {
return 0;
}


If the method call binarySearch(list, "bar") is removed the error is:

Syntax error, insert ">>" to complete ReferenceType2

source:

import java.util.ArrayList;
import java.util.List;

void setup()
{
List<String> list = new ArrayList<String>();
list.add("foo");
list.add("bar");
list.add("baz");
}

static <T> int binarySearch(List<? extends Comparable<? super T>> list, T
key) {
return 0;
}


A static method declaration using <? super T> without nesting works ok:

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

void setup()
{
List<String> list = new ArrayList<String>();
addAll(list, "foo", "bar", "baz");
}

static <T> boolean addAll(Collection<? super T> c, T... elements) {
return false;
}
Additional Comment #1 From MrFeinberg 2010-03-16 13:00
Fixed.
Additional Comment #2 From heuermh 2010-03-16 13:02
This simpler declaration also fails to compile.

error:

Syntax error, insert ", TypeArgument2" to complete TypeArgumentList2

source:

import java.util.List;

static <T> void do(List<List<?>> list) {
// empty
}
Additional Comment #3 From heuermh 2010-03-16 13:03
Wow, MrFeinberg, you're quick. :)
Additional Comment #4 From MrFeinberg 2010-03-16 13:20
:)

I saw your post on the mailing list, and was just checking in the fix when
you created the official bug.
Additional Comment #5 From MrFeinberg 2010-03-16 15:46
do is a keyword; that's why the second example is failing