generics

Java generics: la soluzione del tutorial" Core Java " non funziona su Eclipse?

Sto leggendo il libro "Core Java" di Hortsmann e Cornell (Vol.1). Nel capitolo Generics, suggeriscono un input che è volutame ... metro, ma ora ottengo l'errore The method getMiddle(T[]) in the type ArrayAlg is not applicable for the arguments (double[])

Oracle Java generics tutorial Box classe spiegazione

Stavo leggendo il tutorial di Oracle sui generici e non riuscivo a capire cosa c'è di sbagliato nell'esempio fornito. (Il tut ... n tipo primitivo e funziona ancora fine...so perché si dovrebbe verificare un errore di runtime in una situazione del genere?

Pensiero in Java, 4a edizione, Capitolo generici

In questo capitolo,in Array di argomento generici l'autore dice che tutti gli array hanno la stessa struttura(dimensione di o ... al tipo che contengono. Voglio solo sapere se è vero o no ? Ho anche aggiunto lo screenshot di quella pagina! TIJ4 Generici

Invertire una raccolta generica in Java

Ho il seguente compito: "Dichiara un metodo, aspettandoti una raccolta e invertilo nel tuo metodo. Restituire la stessa col ... Collection.java:16) at ReverseCollection.main(ReverseCollection.java:25) Qualche idea su come questo dovrebbe essere fatto?

Firma del metodo Java-understanding

Quali parametri devono essere inviati a questo metodo Java: public void resume(Collection<TopicPartition> partitions) ... va sopra. Quindi sono 3 parametri o 2 o 1? Per favore qualcuno descriva come dovrei leggere questo tipo di firme. Grazie.

Java generic e getThis() idioma sono confusi

Volevo creare costruttori gerarchici in Java e ho notato che l'ereditarietà del builder non è possibile senza un trucco. Ho t ... ene entrambi i metodi restituiscano lo stesso tipo. Perché new AgeAddedBuilder() non è un T extends AbstractBuilder<T>?

Riferendosi genericamente agli oggetti in diverse famiglie in Java

Ho classi appartenenti alla famiglia Foo (BabyFoo, MamaFoo, PapaFoo) così come le classi appartenenti alla famiglia Bar (Baby ... ce, un genitore di sia FamilyFoo che FamilyBar) significa che viene raggiunta un'economia di codice. Si può fare di meglio?

Programmazione generica Java con tipo di interfaccia generico sconosciuto

Sto usando diverse interfacce con tipi generici. Mentre lo combino insieme ho alcuni problemi quando devo usarli da una parte ... uesti avvertimenti? Come posso usare safety un'interfaccia generica da una classe in cui non conosco il suo tipo concreto?

Java-È sicuro sopprimere l'avviso cast non controllato con WatchEvent?

Ho il seguente codice di test: FileSystem fs = FileSystems.getDefault(); Path conf = fs.getPath("."); WatchKey key = null; t ... iminata o modificata. Quindi nel mio caso sto guardando per ENTRY_MODIFY eventi, quindi il mio T tipo è sicuramente un Path.

Classe vs Classe in Java [duplicato]

Questa domanda ha già delle risposte qui: ... un modo stenografico o la scrittura della seconda riga? Class cls1 = Person.class; Class<Person> cls2 = Person.class;

Numero di tipo generico Java

Ho letto diverse pagine sui metodi generici e ho una sorta di comprensione su di essi, ma ancora non li capisco. Quindi dicia ... pe y){ return x * y; } Come posso usare i generici limitati per avere solo un tipo di numero consentito come parametri?

Java Abstract, generici e costruttori

Questa è la mia prima pubblicazione, ma sto avendo un sacco di problemi con un problema. Attualmente ho una classe AbstractDe ... r method public DeviceClass getDeviceClass(){ return DeviceClass.HUB; } //end method getDeviceClass() } //end class Hub

Differences between extend and super in Generics

For example, the following code: public void add(List<? super Number> list) { list.add(1D); // можно list.add( ... r". And it works the other way around: "any type is the heir of Number". What's wrong? Why does it work the other way around?

What is more correct than Java Generic Interface and Generic Methods in this case?

This issue arose because of the PDF... discussions with a colleague about what is preferable. There is a code that can be wri ... d, 2. in each class where it is used, the interface / method works with only one type, 3. use both options in principle may.

Why do we need and as method parameters

There is a function: <R> Stream<R> map(Function<? super T, ? extends R> mapper); It performs operations ... fter all, we just pass the implementation with specific T(User) and R(String), where can we use subclasses and superclasses?

Generic and arrays

Good time to all! I thought I knew how to use generics, but it turned out that I didn't. Code: class MyClass<T> { T mas[]; void foo() { mas = new T[10]; // ошибка! } } Question - why does the error occur?

The principle of generic Java types

I'm trying to write a parameterizable method that accepts parameterized types: public static <T> void findMinMax( ... ubtype and its super-type. Why then does the compiler talk about type incompatibility? What does the compiler mean by CAP#1?

instanceof for collection java

Hello everyone, there is one method whose input parameter is Collection<E> collection Inside the method, I want to imp ... .println("yes"); } } Here the check does not work on List<SBwCause> it does not check the compiler swears

Java access modifiers

For educational purposes, I create my own implementations of some data structures. You need to create a regular binary search ... Option c getters and setters in GenTree (which I think is optimal) I came up with it already in the process when I wrote it.

Static field in generics/template

There is a Java generics class of the type: public class MyClass<T> { static long myField=System.currentTimeMillis( ... : Are var1.myField and var2.myField the same? Update And if it is a template in C++/C# - then will they be the same or not?