Pracuje w środowisku netbeans, ale teraz przyszło mi zmierzyć się z kompilatorem javac który razem z -Xlintem totalnie sie mi buntują.
Błędy:
Main.java:60: warning: [rawtypes] found raw type: List
List tmp = obiect.blockTable.get(numb1);
^
missing type arguments for generic class List<E>
where E is a type-variable:
E extends Object declared in interface List
Main.java:61: warning: [unchecked] unchecked call to add(E) as a member of the r
aw type List
tmp.add(numb2);
^
where E is a type-variable:
E extends Object declared in interface List
Main.java:66: warning: [rawtypes] found raw type: List
List tmp = obiect.blockTable.get(j);
^
missing type arguments for generic class List<E>
where E is a type-variable:
E extends Object declared in interface List
Main.java:67: warning: [unchecked] unchecked conversion
Collections.sort(tmp);
^
required: List<T>
found: List
where T is a type-variable:
T extends Comparable<? super T> declared in method <T>sort(List<T>)
Main.java:67: warning: [unchecked] unchecked method invocation: method sort in c
lass Collections is applied to given types
Collections.sort(tmp);
^
required: List<T>
found: List
where T is a type-variable:
T extends Comparable<? super T> declared in method <T>sort(List<T>)
5 warnings
a kod:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main
{
static char[][] square; //główna tablica w której odbywa się gra
static int maxBlockSize=0;
static int empty; //odpady
static int square_size;
public static void main(String[] args) throws FileNotFoundException
{
String imput_file;
imput_file = args[0];
square_size = Integer.parseInt(args[1]);
square = new char[square_size][square_size];
for(int x=0;x<square_size;x++)
{
for (int y=0;y<square_size;y++)
{
square[x][y]='o';
}
}
File file = new File(imput_file);
Scanner in = new Scanner(file);
Scanner in2 = new Scanner(file);
while(in.hasNextInt())
{
int max = in.nextInt();
if(max>maxBlockSize)
{
maxBlockSize=max;
}
}
maxBlockSize=maxBlockSize+1; //bo BlockTable zaczyna sie od 0
Knapsack obiect = new Knapsack();
while(in2.hasNextInt())
{
int numb1 = in2.nextInt();
if(!in2.hasNextInt()){break;} //jakby bylo nieparzyscie w pliku
int numb2 = in2.nextInt();
if(compareInt(numb1, numb2)==false)
{
int temp;
temp = numb1;
numb1 = numb2;
numb2 = temp;
}
List tmp = obiect.blockTable.get(numb1);
tmp.add(numb2);
}
for(int j=0; j<maxBlockSize; j++)
{
List tmp = obiect.blockTable.get(j);
Collections.sort(tmp);
Collections.reverse(tmp);
}
/*for(int j=0; j<maxBlockSize; j++)
{
List tmp = obiect.blockTable.get(j);
System.out.print(tmp+"\n");
}*/
empty = obiect.pack();
System.out.println("Ilosc odpadow = "+empty);
}
private static boolean compareInt(int a, int b)
{
if (a>=b)
{
return true;
}
else
{
return false;
}
}
}
Pobieznie czytalem o raw types i generics, mniej wiecej wiem ze chodzi o tagi deklaracji typów ale nijak nie moge zdebugować tych warningów, a muszę. Dzięki