-1

i know this have been previously answered and i have read the answers in How to properly define an array of linked list in Java ? and How do I fix "The expression of type List needs unchecked conversion...'?

And i use this, as is recommended in the second answer of the second link

@SuppressWarnings("unchecked")
public void myMethod()
{
    //...
}

Because in my code (example below) i need to use a static LinkedList[] so after reading the data i will have the size of the number i'll use in "Q = new LinkedList[size of data];". And i need the static LinkedList[] because i use it in many function

 static LinkedList<Integer>[] Q;

 @SuppressWarnings("unchecked")
 static public void function(){
 int r=3;
 Q = new LinkedList[10];//this gives the warnning without "the unchecked"
 Q[r]=new LinkedList<Integer>();
 }
 static public void function2(){
   //using  Q[r] for different r
 }

It's still giving me the warning when i compile

    memoria/bosques.java:3150: warning: [rawtypes] found raw type: LinkedList
                Q = new LinkedList[10];
                        ^
    missing type arguments for generic class LinkedList<E>
    where E is a type-variable:
    E extends Object declared in class LinkedList

Compiling this in windows's eclipse works well, but in linux doesn't

Is there something i can do?

Community
  • 1
  • 1
Emaneitron
  • 83
  • 9

1 Answers1

0

Finally instead of using @SuppressWarnings("unchecked"), i used ArrayList < LinkedList< Integer>> so instead of defining a Q = new LinkedList[4], i do a for to add the new LinkedList:

        static ArrayList<LinkedList<Integer>> Q2 = new ArrayList<LinkedList<Integer>>();

        public static void function(){
        for(int i=0;i<4; i++){
                            LinkedList<Integer> fila=new LinkedList<Integer>();
                            Q2.add(fila);
        }
                        Q2.get(0).add(3);
                        Q2.get(0).add(4);
                        Q2.get(0).add(5);
                        Q2.get(2).add(13);
                        Q2.get(2).add(14);
                        Q2.get(2).add(15);

                        for(LinkedList<Integer> fila:Q2){
                            System.out.print("Miembros");

                            for(Integer it:fila){
                                System.out.print("->{");
                                System.out.print(it);
                                System.out.print("}");
                            }
                            System.out.println("");
                        }

        }
Emaneitron
  • 83
  • 9
  • @Jishnu Prathap , what do you mean? i changed all my structures of Q[r] with a Q.get(r) and works the same and it errase the warning unchecked...ArrayList was a relevant factor to solve my problem and i put a little example of how it works or you say this because i asked about @SuppressWarnings("unchecked")? – Emaneitron Jul 22 '15 at 12:36
  • You were getting compile error while creating linkedlist arrays and you solved it by creating arraylist of linkedlist right? Actually I think this is a different implementation of your program without compile warnings but not answer to your question. – Jishnu Prathap Jul 22 '15 at 13:03