hi,
I am iStore developer,mostly working on jsp pages.
I do have knowledge on core java.But new to generics.
Can anyone provide book references on generics.Or any links relatated to generics can be helpful for me.
Thanks,
Sabitha
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
hi,
I am iStore developer,mostly working on jsp pages.
I do have knowledge on core java.But new to generics.
Can anyone provide book references on generics.Or any links relatated to generics can be helpful for me.
Thanks,
Sabitha
I read a tutorial about generics,but it was in greek.So i can only post you the examples of it,not the link(if you wish the link too ask for it )
package generics; public class Main{ public static void main(String[] args) { Integer[] int_array = {1,2,3,5,5}; //in Generic basic types such as int,double,char //can not be used,so we use instead Inetger,Double,Character.The point is that at Gene //rics we can play only with Classes ,not with basic types(e.g. int).Notice that //Integer,etc. are classes Character[] char_array = {'s','a','b','h'}; int s1=12; char s2='a'; /*Purpose of function contains is to see if a symbol is part of a sequence(e.g. an * array) */ if(contains(int_array,s1)) { System.out.println("Found" + s1); } else System.out.println( s1 + " Not found...\n"); if(contains(char_array,s2)) { System.out.println("Found " + s2); } else System.out.println( s2 + " Not found...\n"); } //The generic type is placed before the return type of the function public static <E> boolean contains(E[] a,E x) { for(E element : a)//traverse all the elements of array a { if(x.equals(element))//equals is a function that is for use to us by JAVA { return true; } } return false; } }
and about safety of Generics
package genericsafety; import java.util.*; public class Main{ public static void main(String[] args) { List<Integer> l =new ArrayList(); //insert some random numbers at that list l.add(5); l.add(100); //Error because the list is for int and we insert String //l.add("this will cause error"); } }