Friday, December 5, 2014

Class " Generic " in Java

Previously we have discussed pengerian of Generic, therefore this evening we discussed the sequel is about generic classes.
One way for the realization of generic performed in class or known by the generic name of the class. Generic class generally used for the collection without specifying the type of data that is stored. Example declaration can search google ya buddy.

In order to facilitate understanding, the author will give you how to create a generic class. The first illustration we create a generic class where we will create a class that can hold one data type .Here is an example of a generic class:

Generic is the best
Import java.util.Arraylist;
Public class mygeneric<E> {
Private arrayList<E> list = new ArrayList<>();
Public int getsize(){
return list.size();
}
Public void push (E item){
List.add(item);
}
Public E pop(){
E item = list.get(getsize()-1);
List.remove(getsize()-1);
Return item;
}
Public boolean isempy(){
Return list.isempy();
}
}

Save the above program code and name the file MyGeneric. java
Explanation Code Program
1. We declare a generic class with menembahkan <E> that shows the generic element.
2. Data stored in the variable list is an instance of an object arraylist <> generic.
3. Make method to getSize (), push (), and isempy ().

Then we will use this mygeneric class into our program. As an illustration of typing the program code:


System.out.println(“ DEMO “);
Mygeneric<String> kota = new mygeneric<String>();
Kota.push(“Medan”);
Kota.push(“Yogya”);
Kota.push(“Pekanbaru”);
While(!kota.isempy()){
String item = kota.pop();
System.out.println(item);
}

Save the code and run this program.
If it succeeds we will mnedapatkan results.
Illustration second, and third and subsequent please wait for ya .....

Keyword :
#Generic, #Generic Pills, #Generic Xanax, #Generic Zoloft, #Generic Loestrin, #Generic Effexor, #Generic Amlodipine, #define generic, #generic meaning, #generics c# , #system.collections.generic, #generic medicines, #what does generic mean, #generics in c#, #generic brand, #generic programming, #c# generic, #meaning of generic, #generically, #c# generic method 

No comments:

Post a Comment