Bug 552273 - Compilation error for legal generics code(JDK 11)
Summary: Compilation error for legal generics code(JDK 11)
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: APT (show other bugs)
Version: 4.14   Edit
Hardware: PC Windows 10
: P3 major with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Generic inbox for the JDT-APT component CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-21 05:40 EDT by Mohan Radhakrishnan CLA
Modified: 2023-01-01 15:11 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mohan Radhakrishnan CLA 2019-10-21 05:40:27 EDT
My reference is the correct compilation in the latest IntelliJ IDEA.


The method newHashMap(Collection<? extends T>) in the type Reference is not applicable for the arguments (List<GenericsBug.TestClass>)

--------Interface1.java--------

package com.generics;

public interface Interface1 {
	
    void test();

}


--------HasReference.java--------

package com.generics;


public interface Interface2<T extends Interface1> {
	
    Reference<T> getRef();

}


--------Reference.java--------

package com.generics;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;


public class Reference<T extends Interface1>
implements Interface1, Comparable<Reference<T>>, Serializable {

	@Override
	public int compareTo(Reference<T> o) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void test() {
		// TODO Auto-generated method stub
		
	}
	
    public static <T extends Interface1 & Interface2<T>> Map<Reference<T>, T> newHashMap(
            Collection<? extends T> items) {

        if ((items == null) || items.isEmpty()) {
            return Collections.emptyMap();
        }
        Map<Reference<T>, T> idMap = new HashMap<>(items.size());
        for (T item : items) {
            idMap.put(item.getRef(), item);
        }
        return idMap;
    }

}

--------GenericsBug.java--------

package com.generics;

import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.UUID;


public class GenericsBug {
	
    private final TestClass testObj1 = new TestClass();
    private final TestClass testObj2 = new TestClass();
    private final TestClass testObj3 = new TestClass();

	
    public void test() {
		Map<Reference<TestClass>, TestClass> map = Reference.newHashMap(Arrays.asList(testObj3, testObj2, testObj1));

    }
    
    private static class TestClass implements Interface1, Interface2 {

		@Override
		public Reference getRef() {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public void test() {
			// TODO Auto-generated method stub
			
		}

    }

}
Comment 1 Tobias Ericsson CLA 2020-06-10 10:21:58 EDT
I ran into the same problem and created a much simpler test case:

class Test {
	void test() {
		get(new Concrete());
	}
	<T, C extends Base<T>> void get(C arg) {}
	
	static class Base<T> {}
	static class Concrete extends Base {}
}

It compiles fine in Java 7, but in Java 8+ it gives the following error:

The method get(C) in the type Test is not applicable for the arguments (Test.Concrete)
Comment 2 Eclipse Genie CLA 2023-01-01 15:11:23 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.