Generics Ajax tutorial



0 stele

867 vizualizari  |  Fii primul care comenteaza

Tutorial Tutoriale programare
Numar pagini: 23
Adaugat de: MariaTim 9 feb 2010
 
Pret: 4 Gold Coin
Download Generics Ajax tutorial - Tutorial  Tutoriale programare
Comenteaza

JDK 1.5 introduces several extensions to the Java programming language. One of these is the introduction of generics. This tutorial is aimed at introducing you to generics. You may be familiar with similar constructs from other languages, most notably C++ templates. If so, you’ll soon see that there are both similarities and important differences. If you are not familiar with look-a-alike constructs from elsewhere, all the better; you can start afresh, without unlearning any misconceptions.

Generics allow you to abstract over types. The most common examples are container types, such as those in the Collection hierarchy. Here is a typical usage of that sort: List myIntList = new LinkedList(); // 1 myIntList.add(new Integer(0)); // 2 Integer x = (Integer) myIntList.iterator().next(); // 3

The cast on line 3 is slightly annoying. Typically, the programmer knows what kind of data has been placed into a particular list. However, the cast is essential. The compiler can only guarantee that an Object will be returned by the iterator. To ensure the assignment to a variable of type Integer is type safe, the cast is required. Of course, the cast not only introduces clutter. It also introduces the possibility of a run time error, since the programmer might be mistaken.

What if programmers could actually express their intent, and mark a list as being restricted to contain a particular data type? This is the core idea behind generics. Here is a version of the program fragment given above using generics: List<Integer> myIntList = new LinkedList<Integer>(); // 1’ myIntList.add(new Integer(0)); //2’ Integer x = myIntList.iterator().next(); // 3’

Notice the type declaration for the variable myIntList. It specifies that this is not just an arbitrary List, but a List of Integer, written List<Integer>. We say that List is a generic interface that takes a type parameter - in this case, Integer. We also specify a type parameter when creating the list object.

 
Citeste mai mult despre: PROGRAMARE  Tutorial  Ajax  generics 
Textul de mai sus reprezinta un extras din "Generics Ajax tutorial". Pentru versiunea completa a documentului apasa butonul Download si descarca fisierul pe calculatorul tau. Prin descarcarea prezentei lucrari stiintifice, orice utilizator al site-ului www.studentie.ro declara si garanteaza ca este de acord cu utilizarile permise ale acesteia, in conformitate cu prevederile legale ablicabile in domeniul proprietatii intelectuale si in domeniul educatiei din legislatia in vigoare.
In cazul in care intampini probleme la descarcarea fisierului sau documentul nu este nici pe departe ceea ce se doreste a fi te rugam sa ne anunti aici: raporteaza o eroare


 
CARE ESTE OPINIA TA?

Cod

Cod de securitate

 

Bursa de inteligenta

Adauga o cerere pentru cursul sau referatul de care ai nevoie iar noi te anuntam de indata ce cererea ta a primit un raspuns. Daca dimpotriva, esti un student silitor si vrei sa raspunzi unei cereri, vei castiga mult mai multi gold coins!

Participa acum!