redhat-developer / redhat-developer/vscode-java

Build/compilation issue with wildcard types

Abierto
#4,059 8 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

compile upstream
Lenguaje dominante
TypeScript
Estrellas
2.3k
Forks
546
Merge medio
20 h 1 min
PR fusionados (30 d)
11

Descripción

Following is some sample code to replicate the issue:

import java.util.List;

public class Tester {
    <T extends List<? extends Entry<?, ?>>> Entry<?, ?> test(T input) {
        return ConcreteEntry.from(input.get(0));  // Error here
    }

    public static void main(String[] args) {
        Tester tester = new Tester();

        System.out.println(tester.test(List.of(new ConcreteEntry<>("a", 1))));
    }

}

interface Entry<K, V> {
    K getKey();

    V getValue();
}

class ConcreteEntry<K, V> implements Entry<K, V> {
    private final K key;
    private final V value;

    public ConcreteEntry(K key, V value) {
        this.key = key;
        this.value = value;
    }

    public static <K, V> ConcreteEntry<K, V> from(Entry<K, V> entry) {
        return new ConcreteEntry<>(entry.getKey(), entry.getValue());
    }

    @Override
    public K getKey() {
        return key;
    }

    @Override
    public V getValue() {
        return value;
    }

    @Override
    public String toString() {
        return this.key + "=" + this.value;
    }
}

The test method throws the error The method from(Entry<K,V>) in the type ConcreteEntry is not applicable for the arguments (capture#1-of ? extends Entry<?,?>) Java(67108979). The expected behaviour is correct compilation. However, enabling the "java.jdt.ls.javac.enabled" works, but is not an ideal solution.

This occurs with the latest Language Support for Java(TM) by Red Hat - v1.42.0.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Reproduce el diagnóstico informado con el ejemplo de Java del issue usando Language Support for Java v1.42.0, primero con la ruta normal del compilador y después con java.jdt.ls.javac.enabled habilitado. Compara ambos resultados y confirma que el ejemplo de tipo comodín compila sin errores en la ruta corregida.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
java
Área
tooling
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
38/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.