This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compilation error

 
Rajat Sarkar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
looks like you dont have type parameters for Arraylist, it will lead to a warning in java 5
 
Rob Spoor
Sheriff
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mehar,

Please read your private messages regarding an important announcement.

Thank you,

Rob
 
Rajat Sarkar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ArrayList<SimUnit> seems to be a better match. That way you won't have to cast the contents when you retrieve them.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic