Warnings when compiling a Linked List code in java -


i trying write simple code implement linked list in java using java.util.linkedlist library. have tried best keep error-free.

it compile (and execute) using -xlint:unchecked. generates lot of warnings of type - ll.java:25: warning: [unchecked] unchecked call add(e) member of raw type linkedlist

can me 1. comprehend why happening? 2. remove warnings!

any appreciated...

import java.util.linkedlist;  class ll{ public static void main(string[] args){      //creating new linked list object     linkedlist llobj = new linkedlist();      //adding data linked list     llobj.add("t");     llobj.add("h");     llobj.add("i");     llobj.add("s");     llobj.add(" ");     llobj.add("i");     llobj.add("s");     llobj.add(" ");     llobj.add("a");     llobj.add(" ");     llobj.add("l");     llobj.add("i");     llobj.add("n");     llobj.add("k");     llobj.add("e");     llobj.add("d");     llobj.add("-");     llobj.add("l");     llobj.add("i");     llobj.add("s");     llobj.add("t");      //printing linked list     system.out.println(llobj);      //implementing more functions add data     llobj.addfirst("#");     llobj.addlast("#");     llobj.add(5,"$");      //printing linked list     system.out.println(llobj);      //removing data     llobj.remove("$");     llobj.remove("#");     llobj.remove("#");      //printing linked list     system.out.println(llobj);     } } 

well, you're using generic type (linkedlist<e>) you're using raw type, if didn't know generics. want this:

linkedlist<string> list = new linkedlist<string>();  list.add("t"); list.add("h"); 

that way you're safe in terms of types involved, , know in list string.

in java 7 can use "diamond syntax" infer type on right hand side left:

linkedlist<string> list = new linkedlist<>(); 

for much more generics (including raw types), see java generics faq. note how in example renamed llobj variable name (which doesn't follow java naming conventions) list. it's idea follow naming conventions @ times, when sharing code others.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -