aspose file tools*
The moose likes Beginning Java and the fly likes compilation error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compilation error" Watch "compilation error" New topic
Author

compilation error

Rajat Sarkar
Greenhorn

Joined: Sep 07, 2008
Posts: 18
import java.util.*;

class V2Radiator
{
V2Radiator(ArrayList list)
{
for(int x=0;x<5;x++)
list.add(new SimUnit("V2Radiator"));
}
}

class V3Radiator extends V2Radiator
{
V3Radiator(ArrayList list)
{
super(list);
for(int x=0;x<10;x++)
list.add(new SimUnit("V3Radiator"));
}
}

class RetentionBot
{
RetentionBot(ArrayList list)
{
list.add(new SimUnit("Retention"));
}
}

public class TestLifeSupportSim
{
public static void main(String[] args)
{
ArrayList aList = new ArrayList();
V2Radiator v2 = new V2Radiator(aList);
V3Radiator v3 = new V3Radiator(aList);
for(int z=0; z<20 ; z++)
{
RetentionBot ret = new RetentionBot(aList);
}
}
}

class SimUnit
{
String botType;

SimUnit(String type)
{
botType=type;
System.out.println(type);
}

int powerUse()
{
if("Retetention".equals(botType))
{
return 2;
}
else
{
return 4;
}
}
}

whenever i try to compile this, some type of compilation error comes.it tells

"Note: TestLifeSupportSim.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details. "

what does it mean by that?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
That's not an error; it's a warning that your code might not be type-safe. I haven't got the time to look up the details, but you will probably find something useful in the Java Tutorials: try this section.
Mehar Simhadri
Greenhorn

Joined: Jan 25, 2009
Posts: 4
looks like you dont have type parameters for Arraylist, it will lead to a warning in java 5
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19557
    
  16

Mehar,

Please read your private messages regarding an important announcement.

Thank you,

Rob


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rajat Sarkar
Greenhorn

Joined: Sep 07, 2008
Posts: 18
Mehar Simhadri wrote:looks like you dont have type parameters for Arraylist, it will lead to a warning in java 5


in that case , ArrayList list =new ArrayList(); & ArrayList<Object> list = new ArrayList<Object>(); is both statement works same.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19557
    
  16

ArrayList<SimUnit> seems to be a better match. That way you won't have to cast the contents when you retrieve them.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: compilation error
 
Similar Threads
Head First Java Ch.9 Constructors and Garbage Collection
Help with ArrayList error
Generics, arrays, and sorting
Head First Java Five Minute Mystery p. 268
sublist of arraylist???