redhat-developer / redhat-developer/vscode-java

Build/compilation issue with wildcard types

Aperta
#4,059 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

compile upstream
Lingua principale
TypeScript
Stelle
2.3k
Fork
546
Merge medio
20h 1m
PR unite (30g)
11

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci la diagnostica segnalata con l’esempio Java nell’issue usando Language Support for Java v1.42.0, prima con il normale percorso del compilatore e poi con java.jdt.ls.javac.enabled abilitato. Confronta entrambi i risultati e conferma che l’esempio di tipo wildcard viene compilato senza errori nel percorso corretto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.